ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilHandlerCollection.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\Manifest\ilHandlerCollectionInterface as ilManifestXMLFileHandlerCollectionInterface;
24 use ILIAS\Export\ImportHandler\I\File\XML\Manifest\ilHandlerInterface as ilManifestXMLFileHandlerInterface;
27 use ILIAS\Export\ImportStatus\I\ilFactoryInterface as ilImportStatusFactoryInterface;
28 
29 class ilHandlerCollection implements ilManifestXMLFileHandlerCollectionInterface
30 {
34  protected array $elements;
35  protected ilImportStatusFactoryInterface $import_status;
36  protected int $index;
37 
41  public function __construct(
42  ilImportStatusFactoryInterface $import_status,
43  array $initial_elements = []
44  ) {
45  $this->import_status = $import_status;
46  $this->elements = $initial_elements;
47  $this->index = 0;
48  }
49 
50  public function count(): int
51  {
52  return count($this->elements);
53  }
54 
55  public function current(): ilManifestXMLFileHandlerInterface
56  {
57  return $this->elements[$this->index];
58  }
59 
60  public function next(): void
61  {
62  $this->index++;
63  }
64 
65  public function key(): int
66  {
67  return $this->index;
68  }
69 
70  public function valid(): bool
71  {
72  return 0 <= $this->index && $this->index < $this->count();
73  }
74 
75  public function rewind(): void
76  {
77  $this->index = 0;
78  }
79 
80  public function withMerged(
81  ilManifestXMLFileHandlerCollectionInterface $other
82  ): ilManifestXMLFileHandlerCollectionInterface {
83  $clone = clone $this;
84  $clone->elements = array_merge($clone->toArray(), $other->toArray());
85  return $clone;
86  }
87 
88  public function withElement(ilManifestXMLFileHandlerInterface $element): ilManifestXMLFileHandlerCollectionInterface
89  {
90  $clone = clone $this;
91  $clone->elements[] = $element;
92  return $clone;
93  }
94 
95  public function containsExportObjectType(ilExportObjectType $type): bool
96  {
97  foreach ($this->toArray() as $manifest_file_handler) {
98  if ($manifest_file_handler->getExportObjectType() === $type) {
99  return true;
100  }
101  }
102  return false;
103  }
104 
106  {
107  $status_collection = $this->import_status->collection()->withNumberingEnabled(true);
108  foreach ($this as $manfiest_file_handler) {
109  $status_collection = $status_collection->getMergedCollectionWith(
110  $manfiest_file_handler->validateManifestXML()
111  );
112  }
113  return $status_collection;
114  }
115 
119  public function findNextFiles(): ilManifestXMLFileHandlerCollectionInterface
120  {
121  $collection = clone $this;
122  $collection->rewind();
123  $collection->elements = [];
124  foreach ($this as $manfiest_file_handler) {
125  $collection = $collection->withMerged($manfiest_file_handler->findManifestXMLFileHandlers());
126  }
127  return $collection;
128  }
129 
133  public function toArray(): array
134  {
135  return $this->elements;
136  }
137 }
withMerged(ilManifestXMLFileHandlerCollectionInterface $other)
__construct(ilImportStatusFactoryInterface $import_status, array $initial_elements=[])