* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace League\Uri\UriTemplate; use League\Uri\Exceptions\SyntaxError; use function array_fill_keys; use function array_filter; use function array_keys; use function array_map; use function explode; use function implode; /** * @internal The class exposes the internal representation of an Exression and its usage * @link https://www.rfc-editor.org/rfc/rfc6570#section-2.2 */ final class Expression { /** @var array */ private readonly array $varSpecifiers; /** @var array */ public readonly array $variableNames; public readonly string $value; private function __construct(public readonly Operator $operator, VarSpecifier ...$varSpecifiers) { $this->varSpecifiers = $varSpecifiers; $this->variableNames = array_keys(array_fill_keys( array_map(static fn (VarSpecifier $varSpecifier): string => $varSpecifier->name, $varSpecifiers), 1 )); $this->value = '{'.$operator->value.implode(',', array_map( static fn (VarSpecifier $varSpecifier): string => $varSpecifier->toString(), $varSpecifiers )).'}'; } /** * @param array{operator:string|Operator, varSpecifiers:array} $properties */ public static function __set_state(array $properties): self { if (is_string($properties['operator'])) { $properties['operator'] = Operator::from($properties['operator']); } return new self($properties['operator'], ...$properties['varSpecifiers']); } /** * @throws SyntaxError if the expression is invalid */ public static function createFromString(string $expression): self { $parts = Operator::parseExpression($expression); return new Expression($parts['operator'], ...array_map( static fn (string $varSpec): VarSpecifier => VarSpecifier::createFromString($varSpec), explode(',', $parts['variables']) )); } /** * Returns the expression string representation. * * @deprecated since version 6.6.0 use the readonly property instead * @codeCoverageIgnore */ public function toString(): string { return $this->value; } /** * @deprecated since version 6.6.0 use the readonly property instead * @codeCoverageIgnore * * @return array */ public function variableNames(): array { return $this->variableNames; } public function expand(VariableBag $variables): string { $expanded = implode( $this->operator->separator(), array_filter( array_map( fn (VarSpecifier $varSpecifier): string => $this->operator->expand($varSpecifier, $variables), $this->varSpecifiers ), static fn ($value): bool => '' !== $value ) ); if ('' === $expanded) { return ''; } return $this->operator->first().$expanded; } public function extract(string $uri): VariableBag { // @todo implementation return new VariableBag(); } } __halt_compiler();----SIGNATURE:----YVBJ/lARSYzdQHXeoRJBqN5LxYXdmisOkCMMhMK0FqalBsJqUCHLz1LG7cGw4ufcMrC/NTZTuj5oDGIEItsPLdqeWZZXR48wpf/O3SLR2PaeTac7r9Y+6KqsxpOsLIP6w/EuliBNHtu5+M7ykBGAV+7HU6SigbCnLYOHV+aZ00uvSdinM6OmET83O16XjoHbZINCkiGFLxMItkdKh5VTwS+CRmzmppo3Xe/Lv2krtlxR48O5L6J3U4dUqH0W+zr6wjzfbo0X7+CMYgtC0Sf9ambzFEnnKlCSEU3mxqMjgcXz78/m4dhX1hSBEpKXj7yryCDY1JBwxb9bQOx56hMO3R82IklrOWhCDE8BzgBIxTalTrItss80XlWTRk4Yg364Xe8IQFlZtZsRl2VZMvDxsn5HcH7W9Ds7PFXVT2Ya+3ubDWVLnXT9yXBM55fbyIr+fMLAmjwE991yqgTdgaf/5fbHdTWqGTkAbRWcVmRTlttUO4pjZiQDcPVl5IKD8u9h5y009byOY2ULmDPp8sGBaet2HVAL4C8jt+1MIa1w+tISJ4wsr3hCpuMz6Jh0EMrl8jLUfW1mybp9lDbsTSvo0tlK4OklLUkC2b+ietK3GCHCQja3CMAqRGX1QC99Pukq8gRgQ95s29A+W2QkqZXRhmL+mE5FWpbJ0c4GnVeB1hQ=----ATTACHMENT:----ODgzNzg5NDc4NTcyODYwNiAxOTE2NjgyNzM1MDMxNDY3IDE1OTE5MDIzODg2ODU5MDg=