ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilCollection.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ILIAS\Export\ImportHandler\I\File\Namespace\ilCollectionInterface as ilParserNamespaceCollectionInterface;
24 use ILIAS\Export\ImportHandler\I\File\Namespace\ilHandlerInterface as ilParserNamespaceHandlerInterface;
25 
26 class ilCollection implements ilParserNamespaceCollectionInterface
27 {
28  protected array $elements;
29  protected int $index;
30 
31  public function __construct()
32  {
33  $this->elements = [];
34  $this->index = 0;
35  }
36 
37  public function count(): int
38  {
39  return count($this->elements);
40  }
41 
42  public function withMerged(ilParserNamespaceCollectionInterface $other): ilParserNamespaceCollectionInterface
43  {
44  $clone = clone $this;
45  $clone->elements = array_merge($this->toArray(), $other->toArray());
46  return $clone;
47  }
48 
49  public function withElement(ilParserNamespaceHandlerInterface $element): ilParserNamespaceCollectionInterface
50  {
51  $clone = clone $this;
52  $clone->elements[] = $element;
53  return $clone;
54  }
55 
56  public function toArray(): array
57  {
58  return $this->elements;
59  }
60 
61  public function current(): ilParserNamespaceHandlerInterface
62  {
63  return $this->elements[$this->index];
64  }
65 
66  public function next(): void
67  {
68  $this->index++;
69  }
70 
71  public function key(): int
72  {
73  return $this->index;
74  }
75 
76  public function valid(): bool
77  {
78  return 0 <= $this->index && $this->index < $this->count();
79  }
80 
81  public function rewind(): void
82  {
83  $this->index = 0;
84  }
85 }
withElement(ilParserNamespaceHandlerInterface $element)
withMerged(ilParserNamespaceCollectionInterface $other)