\{[^}]*})/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:----HpESWwS5q3oRWPGjr4ovBSPesBuiSo1Zs5kTQ/L5GB8y/JS07AZu+PEAsDCsD3XEIXM6A4AP02x5Yhr5shi2bT+005H20yX2Lu7bCtALu6TAcoZEqjNgz9p4xT6u119riQecCTYuPCouYxbjUI8XKsg73aU5RpS356Z89nAk4MBNY6z+365bnzkTr5KuUrxUa4aFbF1CviosK2D6tX3IC6xA/A5JbcI8/YsQXF6UUEGTbTyvK+wXQzy5v7OZxgGxNzJh1Y6z1yAvyrBMWcADWOqOV4vLoDx8tZXgdhMRFffUG1ifaLkIuYKJ1hWGhwTKtybyRe4nFLktnCEs2jGGjgnLifj8C7IpeCWH7HK3dV6/VxgG3CEzuk5yYLm/MMPmEFF2PN20cCdrcJK3KrfcosU618r8HrR+0ojG7U8f09ewleW1wqGC9Y3WTNr4H/RPJlUpgpiHMNQ/ekuBgyJI92FRTkmS+myUBxSE1iX0g4SYVtB6YCEwGxU66072SSFrMGxCdRfrA/kfQYUA8UezqUG35A8Ir3U8tcozX00CN/zbI2gxTKijSlAYAlNQr7kMmDp41XnNDCukZI3xfTe3zajTYSFA24hhStYiFPzPMGmJI/mABjOsy8DFLLuCd/4iQJ2XKuCSyjnwtdnaku7Uw1gSvipzjvowi+ixnMgVhQg=----ATTACHMENT:----OTU0MTM1NTAyMjY2MDQ5MiA1MTA5Mzk5Mzg1MDU0NjgxIDI5MTA3MTMxMDg1NTA2MzQ=