* @implements IteratorAggregate */ final class ValidatedParameters implements ArrayAccess, Countable, IteratorAggregate { /** * @param array $values */ public function __construct( private readonly array $values = [], ) { } public function count(): int { return count($this->values); } public function getIterator(): Iterator { yield from $this->values; } public function offsetExists($offset): bool { return array_key_exists($offset, $this->values); } public function offsetGet($offset): mixed { return $this->offsetExists($offset) ? $this->values[$offset] : throw InvalidOffset::dueToMemberNotFound($offset); } public function offsetUnset(mixed $offset): void { throw new ForbiddenOperation(self::class.' instance can not be updated using '.ArrayAccess::class.' methods.'); } public function offsetSet(mixed $offset, mixed $value): void { throw new ForbiddenOperation(self::class.' instance can not be updated using '.ArrayAccess::class.' methods.'); } /** * @return array */ public function all(): array { return $this->values; } }