> */ 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:----SG4vu7cemRLFhiY03bP5QvVrJ5+DZjHUj0FY4ENHKSgUPZ3TST3ctH5GE2cWrXoacoYBlrVGLB74wByLKL0aj+n3G+qBuQuKWH2CDkAfTUc/Xco0TwPF7UXoEbj5XR9gvBcRj/bp4FoLslPa/b9G8Nn2FbwV+FhCSC7YCfgYE11SDOlcQdq4ol7MGOedmPbpuV1HPgM86YGW5eblo1XXtRklqk9t7npLtXzsHWPpLjFEFKbO+PPdu6pGJDNFSA6Cn/39g5Klp84N18VCqqQcoRARPGap3GDedxhT1gIHqrIRYxTnPhm0fLu9LBRDI1p95IRtYR3113EIAihdxCyvQ9BDpTe2lz1A2JUzYN2QvHDpA4++2t51VXnYck+J0cZcSW4mn7BjKABw35TP+QJeeeIKppfA3/2RZr3R3Y8Fgsc2a0xp7ASKetTFtjUCkcKyXLDCQHgnZdQTxSkvs74xBIY779sFUnlAM2PrZ5ctAOtxeDA7SI3t37dj1NjKBjm76IOAlOlc83vidpstKPUQ+9aj7VgW5N39E0OFtyL9x5+lI8VE63vb4YaIw/gViyFm2qBHKd4jiaxQnSQqqqtls2C7uWvVYOIulrymM6euQK230VEbHiQcFVuM0KGpi/6/V3PGk41asxgYoUlAfD//b5BM/eg1mkJBfFFpWbmCkDE=----ATTACHMENT:----MzE2MjUwNjUxODUxNzYzMyAxNjcxNTAxNDE5ODEyNDAwIDY4MDU4MzIyNjYyNTU2MjI=