ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Collection.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ILIAS\Export\ImportHandler\I\Schema\CollectionInterface as SchemaCollectionInterface;
25 
26 class Collection implements SchemaCollectionInterface
27 {
31  protected array $elements;
32  protected int $index;
33 
34  public function __construct()
35  {
36  $this->elements = [];
37  $this->index = 0;
38  }
39 
40  public function count(): int
41  {
42  return count($this->elements);
43  }
44 
45  public function withElement(
46  SchemaInterface $element
47  ): SchemaCollectionInterface {
48  $clone = clone $this;
49  $clone->elements[] = $element;
50  return $clone;
51  }
52 
53  public function withMerged(
54  SchemaCollectionInterface $other
55  ): SchemaCollectionInterface {
56  $clone = clone $this;
57  $clone->elements = array_merge($clone->elements, $other->toArray());
58  return $clone;
59  }
60 
61  public function toArray(): array
62  {
63  return $this->elements;
64  }
65 
66  public function current(): SchemaInterface
67  {
68  return $this->elements[$this->index];
69  }
70 
71  public function next(): void
72  {
73  $this->index++;
74  }
75 
76  public function key(): int
77  {
78  return $this->index;
79  }
80 
81  public function valid(): bool
82  {
83  return isset($this->elements[$this->index]);
84  }
85 
86  public function rewind(): void
87  {
88  $this->index = 0;
89  }
90 }
withElement(SchemaInterface $element)
Definition: Collection.php:45
withMerged(SchemaCollectionInterface $other)
Definition: Collection.php:53