\{[^}]*})/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:----A/Rd3N1NHYcMc0U8AhlgNqb5Lq65M5AUneb5rgEx6CExLggjmM+YK8o66W83dbneZELNlkJeuFIEoRLrHftA8AG968+CiRi4uCL3vzdzvQXf7+0f15t6mx/VKNuxxIU+QJgHtTEfcI+mB+jVMD8UPBs+Osu2hO3lKOwCVem13Pp/JiPiTi5DsfXyunhiELeZm5Qbg6r0Esly8N6HtK28F/1SENIaPG6l8aNLu6r+8yNn1rnohSOHk0NxLLnqBIXs5/v0ORe0CLK9VnSBWfM/AhkCeE1AWs/Y7pnijzy3mUbEk8N9l2e2soorB9oNELl/SFp+mxKaNGGAuxXyjKDGoadlUsFGlrE3oSyciU/5v+xMRSd+JdGXcGnUmuKWe+KzlzPsrtOeUm2+qaPeM2tDVcoazCP6x/E5yy08Hobykhr8+iBnbEw9NHDvMBW6+IIUCti328//QKLYBbkZU3m8Qf87zQ4qEaLmtzfjy3JQvi1h+8NO4TIvhaulCdYK/MF53H3qUEAmPhw49/679lbcb1Rj5Kz3kytXrUscth+eKHoBfLnIGBe4msgOxrMkuN4+ku/Hu8HJJ9oJyfmJcNeEZlmeLIVnTT3K7WPjzphaTjsdsAhzCFzqHksFPFt7yhVpJKksgvuAEtKcTwVfGXVkDanP00vFz9iiliCX8AMhFWc=----ATTACHMENT:----OTU1OTkyMzk5MzY4MDQ4MCAyMDc3NTczMTY2OTYxMTE1IDIwOTA4Njg0Nzk4NTc1MzY=