* * 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:----UhOvTqgZI2MwpVIlyhILVBrFwiOXNs4Fu3x6VV0MLoyl0aurV/xLMsmQUPV8czfHgdA+WFd5657Dkx9NS9yDiu+YHgbemtZiOn+0GWT9II4YurIe2W52YkEiDjwHj80oAsx9bLvob3gaDJTE11i73jywclQpdT0m1phdIg9UX33iBMzCc2e483SAs0joj6cX6UbLuouqd6eaAvu1kevXx9V+b0VOD/HrILbBP+lGRRgHpxrWPDpb27y7Drm3OUY8MzaEw8cmCww0H1zee6MVyV2cEZDOIGcoi+y94C/3ceFerFZ1Nz3uVkzgYOMB6CtajiofzIo3RF0hx5s97GIG5zq8Rf0v2AVh0o5p7eV8UL5LqIbqnRcUlUUXQe4YmsSTQFhazxy6Qgzk9P9gfZ+ne+b67TLJ/9YYr9KB4kg1x5BKfwKRrLygNhpPoiF8qr6fZ7FdukO3hNNrL+xNmEg53JOfAWkIJh/bly2V9UfQC6rpzpBwWKlbRM9Qxe8ur2NZk/n1hIVz98xObDQbvCLZZtT0nX5RfdOWu9EIMi8v24fUek2u/cx2GczmYd0No3nVf6bHH+qwjXC6+r9DysMWH5bwmymneWrkoFBmblzUdtOadj07bqX13H5xIHuyVJynpZqGC+Z0/0FP/Q27JUs/wjnnoqZTHllVAs06bwAv0gU=----ATTACHMENT:----NDQ5Njc0NzA2ODMyNjk5MCA0NTUxNzI2MTM2OTQ3MDk5IDY5Mzc5MTEyNDQyMjQ0NDE=