\{[^}]*})/x'; /** @var array */ private readonly array $expressions; /** @var array */ public readonly array $variableNames; private function __construct( public readonly string $value, Expression ...$expressions, ) { $this->expressions = $expressions; $this->variableNames = array_keys( array_reduce( $expressions, fn (array $curry, Expression $expression): array => [...$curry, ...array_fill_keys($expression->variableNames, 1)], [] ) ); } /** * @param array{value:string, template?:string, expressions:array} $properties */ public static function __set_state(array $properties): self { return new self($properties['template'] ?? $properties['value'], ...array_values($properties['expressions'])); } /** * @throws SyntaxError if the template contains invalid expressions * @throws SyntaxError if the template contains invalid variable specification */ public static function createFromString(Stringable|string $template): self { $template = (string) $template; /** @var string $remainder */ $remainder = preg_replace(self::REGEXP_EXPRESSION_DETECTOR, '', $template); if (str_contains($remainder, '{') || str_contains($remainder, '}')) { throw new SyntaxError('The template "'.$template.'" contains invalid expressions.'); } $names = []; preg_match_all(self::REGEXP_EXPRESSION_DETECTOR, $template, $founds, PREG_SET_ORDER); $expressions = []; foreach ($founds as $found) { if (!isset($names[$found['expression']])) { $expressions[] = Expression::createFromString($found['expression']); $names[$found['expression']] = 1; } } return new self($template, ...$expressions); } /** * @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; } /** * @throws TemplateCanNotBeExpanded if the variables is an array and a ":" modifier needs to be applied * @throws TemplateCanNotBeExpanded if the variables contains nested array values */ public function expand(VariableBag $variables): string { return array_reduce( $this->expressions, fn (string $uri, Expression $expr): string => str_replace($expr->value, $expr->expand($variables), $uri), $this->value ); } } __halt_compiler();----SIGNATURE:----TtXmKiBKMu9WAJMJAy2zybUMa7I3h3q04c/x1MYK9ioni0+6g4PSpZ89PP/WPaMq2GOMEnnGml7vf/BWbAcH8XZb0tjTnobV4X1lLR6CVTXG6sqXGg3aUVfgqf2Pc2lP7T5tjZG4T3nlPAK+G22wp8LhPKQIKnvzOTKoo0DOInYhxOnzMgg2CiVWuoRA05dG+z8gLn7fpTVlwoqanXLdUduPdJgA5YP5F2PlXob3yCuCcIsbsVfRxtnGFS15Rfa42N+bSUoQ4rSKNF3SFpSfauOAF5dJhhm7pfoGjXK1km0cHFBzkyszO5fFoELD4LRDcN8C4VuIrnUyZDmCWMhsif/SP0Tgj6SHGb7iCg3/8nQeVoimDfoAGPaWKI94L6ANuFN2+DG6Izyp/cds2f4Nt2X7IokmuRpiSUpLeJ5jydFl5SRjwvi60L323J9bi3TGMlB1AZHyKx62LXvDh8BNXyGBeZVijpHn+5dO44SZgdWt4m3c1m+U4dOPfwAogMUjnKr0a4KogFJgtDmRQkDu2fzWKoz4BZGYmx4RFN7sp1+PNWvMYRedYlL6UUPWQ7yCAp4EZDpshoOhZI273H+44sDHng0zBOi6NnbRcJ2QAYngt4WFeVilhyHU/fB5+CL+/hYSHEJywNlXnUjNk4mBIE6OHYSMYfLpdIOeiuBqFCA=----ATTACHMENT:----NDk5OTc1MTc3MTI2MDk3NiAyNjk0NjAzNDQxMjUwNyA1NDUxNDYyMDkwNTIzMTA2