. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU Affero General Public License version 3. * * In accordance with Section 7(b) of the GNU Affero General Public License version 3, * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ namespace Espo\ORM\Query\Part; use InvalidArgumentException; use Iterator; /** * A list of order items. * * Immutable. * * @implements Iterator */ class OrderList implements Iterator { private int $position = 0; /** @var Order[] */ private array $list; /** * @param Order[] $list */ private function __construct(array $list) { foreach ($list as $item) { if (!$item instanceof Order) { throw new InvalidArgumentException(); } } $this->list = $list; } /** * Create an instance. * * @param Order[] $list */ public static function create(array $list): self { return new self($list); } public function rewind(): void { $this->position = 0; } public function current(): Order { return $this->list[$this->position]; } public function key(): int { return $this->position; } public function next(): void { ++$this->position; } public function valid(): bool { return isset($this->list[$this->position]); } }