* @since 6.1.0 * * Based on GuzzleHttp\UriTemplate class in Guzzle v6.5. * @link https://github.com/guzzle/guzzle/blob/6.5/src/UriTemplate.php */ final class UriTemplate { public readonly Template $template; public readonly VariableBag $defaultVariables; /** * @throws SyntaxError if the template syntax is invalid * @throws TemplateCanNotBeExpanded if the template variables are invalid */ public function __construct(Template|Stringable|string $template, VariableBag|array $defaultVariables = []) { $this->template = $template instanceof Template ? $template : Template::createFromString($template); $this->defaultVariables = $this->filterVariables($defaultVariables); } public static function __set_state(array $properties): self { return new self($properties['template'], $properties['defaultVariables']); } /** * Filters out variables for the given template. */ private function filterVariables(VariableBag|array $inputVariables): VariableBag { $variableBag = new VariableBag(); foreach ($this->template->variableNames as $name) { if (isset($inputVariables[$name])) { $variableBag[$name] = $inputVariables[$name]; } } return $variableBag; } /** * The template string. */ public function getTemplate(): string { return $this->template->value; } /** * Returns the names of the variables in the template, in order. * * @return string[] */ public function getVariableNames(): array { return $this->template->variableNames; } /** * Returns the default values used to expand the template. * * The returned list only contains variables whose name is part of the current template. * * @return array */ public function getDefaultVariables(): array { return $this->defaultVariables->all(); } /** * Returns a new instance with the updated default variables. * * This method MUST retain the state of the current instance, and return * an instance that contains the modified default variables. * * If present, variables whose name is not part of the current template * possible variable names are removed. */ public function withDefaultVariables(VariableBag|array $defaultDefaultVariables): self { return new self($this->template, $defaultDefaultVariables); } /** * @throws TemplateCanNotBeExpanded if the variable contains nested array values * @throws UriException if the resulting expansion can not be converted to a UriInterface instance */ public function expand(VariableBag|array $variables = []): UriInterface { return Uri::createFromString( $this->template->expand( $this->filterVariables($variables)->replace($this->defaultVariables) ) ); } } __halt_compiler();----SIGNATURE:----ayevOFBvsWoF9pwGH3nLOHSjfMusKC5vobU+hmf7a8MkQAyKvOvVz9Wz1EcvfVRkQebAW2s/V/D3MqAmUIGiqA99L2tTWPfm2d+XOpUPLO+pFKnsCKN6IkXQB3fyI7nTX+obWNwsO8HEn3Zrby1FAiHMD0+lg8Am1PPVeKxZFZI22IWDvsUYIqngFg3WbO/vTlnL705Gsiy24A36W+5IRUzhTYn3QvC6TgJ/nYy0z7LKGRD1t+qPNOL1yGoR5SqbSN6fm61ccYauTOPS3FBD8gDhKXydTYPYhzC6zVp0tqBJ6Mmy5razQDx5V0zDEu/mUbiei23U1+vAZM38JApvi2WT0w/Jkty2F3edyy6O3eAu9w/8pCu+L87XkQAbLVm7D/xgoAm7ijfdJMpRBGECsLV9h1GvrpbOvGOsgR6iV4DpFdefsFcFeiKIhaXhdOh8L6kM1hXBiqJOSVBrXOFTog4P4okWCvxA+QVm6tSfYERTtYKEsUxeDRtTsq/9OMJfcz++J0XXIjmUSvFuLfzhULeB2SlBxp55re3RSgrBkTRVqaGkTCt1RbxvAoec8GS0pRb1WLglCiO6+F+NZiH/HWLD3mA26Qc03WouZDlLQhuZsnv62dMEN/XarDsk8Z2GyPitPJYkRqdLNe+CIV6/pWBnMeBHCL+SSnEhkNiQ/dA=----ATTACHMENT:----Mjk1Mzc2MDc0OTk1MjA5MiAyNTc2OTY1MzAxMzgxODI2IDE2Nzc2NDI4ODEwMzk3MTE=