> */ 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:----Gk7BadJrfrljx36m7PPRRy5sAqI7DIqJxEkuHnX/hHyL+cU+MGWqqxeeHtc3k0kRMZzs+fL0feDD1zymrYC+f3jEmaY8P2jmhcOpxj5/4BEFpgWjQvwENJKCiWtFB4jl/USTkXbgiUyFh0WbNgmsOuQERZ43yPHqCHBDxLZKZ1bRF+p01SkllnwR44hB430PHzjlrCxYRoNcVWDcB/9AOMV/SHEUaKmRgCAaWtXrYX2hJKWPIwSn6H/D78cxT+5JM0S77l0NC12kvjbg0ta+aqtYAjgl7Roodt6YAvTEIsJeFOyyPKnuvpgyAlf6jXMsotCPJQh+c52M70Gwiq3Se7uaSLuT5l145w1AYaojvZLBveBAatFBS1dlI47nioAiLIfZLYSO0dAc3qJGTCggcsjt/daS6WY7NAsd9JU1JQMFjjGboGjlesMDdDM7CL57yw9DkKelP8fkDmK05QgYg2y/fDyEOIsN1xqqc2ARg4vlKd+VKFNQ/qZ03LCKaVt4w0DvSMojxvjWadzi7oLCq0hmEOcOmiMonKIk+Pgh+JA/K9mQq0qfm/B2nN3HxRdYeaLsg5e6syNc3J9XhYspwKgSaea4gXqg1uhRheMxY4jWT1CQvCgx6AZsvnWJOHFceo+Tb5xuv1u+JwNcP9KBg+HfQ8n+fyN2ljsLZjI4g9c=----ATTACHMENT:----ODU5MTczMTgwMzIyMTMyOSAzMDE1NDMxNjM3MjQ3MTgxIDMxOTU3MzY2NDY0NzY4NTA=