* * 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:----GUc9yF85dVSIMw2e3Rt8FtarfRqcMR4JA6VUIsDEEMKc3yo2+g9Yic+rensgSzf/ACaGzaNwpr6jny1Itjn2dPmqoEAfglcrP27PMc2swAAoe+LLw+NO2BsTESf7dfGEc5ayy1dOHjpP66XBrFRJQZJwVGKq+hWCQ26e7Y40fslN5/0ubgsAtu8LAPmXnftZezSzkqXH7g/1frQxuDUTyxuVbG3FzbQIx739Ig3sJmaBTqQRTBAbLRwVbTAz4eWFd3Aox7RlQyxABph/bkyKGtQO1+4L5WMdY0tRXsR4GAGXMxtIpcqxlgwS4o6s3dmXC3VvU8X3DJCZyvbqEa3PrH2iDaXpwMPN4f2VFDvLmoFUk3o9Zq+7O6dzEDjPRmVcB47LJ9Hn0rUBuuSmUwo44z6nZMxULNYQq0+MeMzDiHGVHidT1KfKSPv/+XBoR2/oe0mPzr2BfXJjjbamCHe/Ksga8HOexOjxLSKP37i8ZmavZcmkC+sv7hXrJINjnbgqCdzBAdt/S4Dob6qY4+plw6RsRq30haP5ol44civHrJPhxx0pN6tOyPq/hAAVW5LD+19nwQ8FVq0Tps2e5uDJxUa+SgzrWhTOJ5k5tdrLid4S0eHdk90ZzkkG0ux4Te4UaJ0u6kXbeCbJCMqWVaw/lLCfATeftr2YcCrpATDDMPQ=----ATTACHMENT:----MTkzNTI1NTA0NTcwNTQ3OCA4NDEzNTYyNDczMjE5MTIyIDk3MjQ3NjI2Mzk1MDQzNzY=