* * 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:----uajZsYqPx3hCQSr3XhZybtEHKUUz7HSK3oDRllf1aeM7zSy5Pr0iOzUongZ2UpcSIuuWQEtGZAB20VtSGhLhBUFHIWwK/7OGDRPX3HwoHoYPX/j70vum6F7BunnlZ87eztnd08r2h5c8I97VIJzP9ybLjq6oHwu66WyeyYhzp78h0QfOmEGsxatIU55yiJ3I49lThmhtWp7/WRu/MOv8IQ1eI8Cvdzt4bIEF7gBmaW9hErhNGVQXIxL5JoHI4NmaUHoTIaAyBJBAIr741uimFa2WiuPGLD+mWfH91s1ezpK1c/8d09FUbjsQBwvcFsSCse/7Q1xD0OuU1E/2xiNVvLNDg7ZhXXf/aUVjkFISx+oCMc/Ip3kGQnxYAlpBjfWaa2B4BniP9rW/q8OwaAxZ+TdM9s6mjWIiaaFD1p0Vj+47Sl3EKVC0w4m74Q0wmRFGwN9i11cPdvEUD+/QArBvMOlUsyOuyn4q3s0yjkuHvaAEG9cwjz37yTkEm8kZn0NBEQnlFRGoXOviyl/i6Blk0/vGo5uPrHnMfbsxmiF/bjmxap9Pj8kBExdquGgpm/FlEd6mvKbCgAkAKj8HRsSZEhOmlQj2p0vGi5rLUE1n/MdsOoh4eaNQ8zLpq96LALL0idniI1eU6PG4zCfz+dxzx3WITEkLCRMIXupgqVrFpY4=----ATTACHMENT:----MjcyNjM2NDUxODIwMjUwMiA0OTM0MTExNDU1NTk1Njc2IDQ0MTg0MjMxNTE4MTY1MjQ=