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\XML\ilCollectionInterface as ilXMLFileHandlerCollectionInterface;
24 use ILIAS\Export\ImportHandler\I\File\XML\ilHandlerInterface as ilXMLFileHandlerInterface;
25 
26 class ilCollection implements ilXMLFileHandlerCollectionInterface
27 {
31  protected array $elements;
32  protected int $index;
33 
37  public function __construct(array $initial_elements = [])
38  {
39  $this->elements = $initial_elements;
40  $this->index = 0;
41  }
42 
43  public function count(): int
44  {
45  return count($this->elements);
46  }
47 
48  public function current(): ilXMLFileHandlerInterface
49  {
50  return $this->elements[$this->index];
51  }
52 
53  public function next(): void
54  {
55  $this->index++;
56  }
57 
58  public function key(): int
59  {
60  return $this->index;
61  }
62 
63  public function valid(): bool
64  {
65  return 0 <= $this->index && $this->index < $this->count();
66  }
67 
68  public function rewind(): void
69  {
70  $this->index = 0;
71  }
72 
73  public function withMerged(ilXMLFileHandlerCollectionInterface $other): ilXMLFileHandlerCollectionInterface
74  {
75  $clone = clone $this;
76  $clone->elements = array_merge($clone->toArray(), $other->toArray());
77  return $clone;
78  }
79 
80  public function withElement(ilXMLFileHandlerInterface $element): ilXMLFileHandlerCollectionInterface
81  {
82  $clone = clone $this;
83  $clone->elements[] = $element;
84  return $clone;
85  }
86 
90  public function toArray(): array
91  {
92  return $this->elements;
93  }
94 }
withElement(ilXMLFileHandlerInterface $element)
withMerged(ilXMLFileHandlerCollectionInterface $other)