* * 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 ArrayAccess; use Countable; use League\Uri\Exceptions\TemplateCanNotBeExpanded; use Stringable; use function is_bool; use function is_object; use function is_scalar; /** * @implements ArrayAccess> */ final class VariableBag implements ArrayAccess, Countable { /** * @var array> */ private array $variables = []; /** * @param iterable> $variables */ public function __construct(iterable $variables = []) { foreach ($variables as $name => $value) { $this->assign($name, $value); } } public function count(): int { return count($this->variables); } /** * @param array{variables: array>} $properties */ public static function __set_state(array $properties): self { return new self($properties['variables']); } public function offsetExists(mixed $offset): bool { return array_key_exists($offset, $this->variables); } public function offsetUnset(mixed $offset): void { unset($this->variables[$offset]); } public function offsetSet(mixed $offset, mixed $value): void { $this->assign($offset, $value); /* @phpstan-ignore-line */ } public function offsetGet(mixed $offset): mixed { return $this->fetch($offset); } /** * @return array> */ public function all(): array { return $this->variables; } /** * Tells whether the bag is empty or not. */ public function isEmpty(): bool { return [] === $this->variables; } /** * Fetches the variable value if none found returns null. * * @return null|string|array */ public function fetch(string $name): null|string|array { return $this->variables[$name] ?? null; } /** * @param string|bool|int|float|null|array $value */ public function assign(string $name, string|bool|int|float|array|null $value): void { $this->variables[$name] = $this->normalizeValue($value, $name, true); } /** * @param Stringable|string|float|int|bool|null $value the value to be expanded * * @throws TemplateCanNotBeExpanded if the value contains nested list */ private function normalizeValue(Stringable|array|string|float|int|bool|null $value, string $name, bool $isNestedListAllowed): array|string { return match (true) { is_bool($value) => true === $value ? '1' : '0', (null === $value || is_scalar($value) || is_object($value)) => (string) $value, !$isNestedListAllowed => throw TemplateCanNotBeExpanded::dueToNestedListOfValue($name), default => array_map(fn ($var): array|string => self::normalizeValue($var, $name, false), $value), }; } /** * Replaces elements from passed variables into the current instance. */ public function replace(VariableBag $variables): self { return new self($this->variables + $variables->variables); } } __halt_compiler();----SIGNATURE:----UL7RgsWxtvGwsf9ijzcqkK6UASoXbpT9JyDhY0/1FYPM+MRuO5fEGt6ResAnMuXdCKjHw0Cxu8Aa7QnDU8AgM5iy2QgbeXfvZU4ol/wW9oVd9f0zki4imTQHxJeljqFYvm4if6Ahwk1kxTEqab3yCMU+jg7dzbq3Ijffv8wfzTBQiU+D1RMJV7MZepIjQKBzFnwuBcc+3TEnYG4h0oPZlwU446vETxf6rGqhUtfmcF4ZfGyb5hD/Hm7ieMgxh4DUXMrz6Q3X1mmZdkbUHZA8WuVj1qnC0TuyJO8K3tC5bIBrGDMNZea2T5EhTh1iZFRvPpOm5KRIF75QL0A9HZrDwDaLnLy8siMp4J9ZQInheUV11Ns2g2JNO230qMXCGw4jQU+4Muq3P0LZ5zLGawoZVO6gqPHH6RWPa4KvTmzXLIZJax3ZNVQWs/zKT1OABVwiwXoEzdGSWTu8Ni6wZ2jCDiQOf+//4aJ8Wxh4J1nj+B3IzX0gtNxL1AiIzl9Sz19LMJSXZMjMTJZIvT2AtzItRRvJJzpcnnO/WGCBQPu9+knt5DrBQspihOPI+2YLMHVOg1hUBxj6ZtXP/TRwQ0CetwMYem/KNIiTtKhNktIV35W6SNtNpHzqCfT9cGxd6eExlaYwAXq5cNzxGwkAmMt1oCcVQJJ1CZgQaV46/sojKtA=----ATTACHMENT:----Mzk1NTkwNTM2MjUxNzY3MCAzODY4NDEzNjQzOTg3Njg1IDQ4MzkxNTE0MzI4NzU0ODA=