> */ 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:----YVyPKCKaG0T7aPHav6Gf/5PiR65wbzh5r8lwCdsYGEcZ7h6B1VlIsJo+Lj6a53EL0kSlNByJI4p26fcYSlfO4AZ1ZmuJcmMimR+bKvnaik1RQsupN2CwSBweJnhOhG4DFdB/YqgEE3H+g0e0Z2fSqC5+dCii2bxp1YvbbdqXgi+ZKKPgeJj18dRdQVAPGuR+fCQUNBu9XlM0izsO0f2iZCUHZgwpi1E3PFPTyaQMi77b1i6BhnZHB8ecLCaC6bZuROnGjXTpkhXBe1TXAfNC11iLWS6SQh8OCvWZzI+Q+4fNo1Hvv5zm+o7KBeliNi4Dsfx/eSBSQRiSWZr9GHCEeCasv11FseuCmbfdqdqeIzs/E9E+yXWd8Or04SnY7FPsQLzceQnv16KnbEsNsseBTSEmMj/JYywMaFcCHrhJRuj8ujEUFS0zeB/AheYpDzlMl1F/iymBmWx+/APN8+1hYhOa8dO0O+rauYEvnOpj6K5UY8pi0xr+lqEecAvif1+cD3nW9v2HTDujr3856PflTGpviwejNFrOZRt5Iv+9Ga/x8Nr3K+WnDDdXuko58hBpVQ8ujASqygDdMBbhUCkotFIVOvLhkz20+vDhc0nFckO7aBUQpKWdQPxcnlAMw+2my/qy4RrckXFUX4D3KJy20+EGWIhHcKzJeezzyXDcUCw=----ATTACHMENT:----MzI1MzU2NTQ3NDk3NDYyNSA4MzQzOTQzNDI3NDIwNjcxIDY5NTg2MTU4NDg0MjgwNzg=