* * 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:----x8rMg9uta3uFyDzGq6s7PWHDgzhg056GhAJDZeJa9y8EtjdcdSH3NJSoD9yz9wQiO8VI00m1Yc2bV9eKMdPPWHNafGwF/xfqwUzf9SZp/Xm+Kb+t9yq8igeB+Y1tIQO8iCU602ZJE9Z8BnO7qqtRdHAjS/rAcfGvrkYC2nDL8FRCjoIUMhX1RU1gQZfLGyTA8DsVI4FiKsE7ewayxf6gOPkUjZ4wGGEOL2lZs+A1xJg5tqW1vJPcBxuIzqVh+9TkjTV1u9wNpxl6g1MWv68nNxjwBy+lYFFza0y8TDZchYGfqFAU2QJZyIDblpz8GHsMa5IxsLQjta3Ei8+DUEych+Yx93pWEYyVJM/kdMYElIVg8KOU+PYp8FW8uHM59AUXElt+KH70BuCpQdkmjLPyW3xl1Ahz5JwTeoFNZs50d4lytOhsHaefk4YQKVDfnbKURisKW55sMmLAN84pBeZ64JuQsuk+C29sUN5NrHngzBpIp6BFP7cZMnWPNZV4t3xW8YFy6EyEE+lR34AataFdhBsOJguiLnkRMqXcmibLcI7CfVXq3spZJ5+Zn9fZxq+HxL54/+4LgfPkpwG9ZNyd3YvSQBMCjvbQs+ZgOj+pFuH4tdW9BxLF7AsoYTHGzxY1M4R3vS7YiP1UtVojmqc4rQbXsbvOK/jHsAi1fOmbfbI=----ATTACHMENT:----NjU4MDc4ODM2NTI4NDM1MyAyNDQ0Mzc4NjU4NzA4MzQgODU2ODI4NzkyNzI4MDI2Mw==