ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
LOMStructureInitiator.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\MetaData\Structure;
22 
33 
35 {
38 
39  public function __construct(
40  ReaderFactoryInterface $reader_factory,
41  StructureFactory $structure_factory
42  ) {
43  $this->reader_factory = $reader_factory;
44  $this->structure_factory = $structure_factory;
45  }
46 
47  public function set(): StructureSetInterface
48  {
49  return $this->structure_factory->set(
50  $this->getStructureRoot()
51  );
52  }
53 
55  {
56  $reader = $this->reader_factory->reader();
57  return $this->structure_factory->root(
58  $reader->definition(),
59  ...$this->getSubElements(0, ...$reader->subDefinitions())
60  );
61  }
62 
66  protected function getSubElements(
67  int $depth,
68  ReaderInterface ...$readers
69  ): \Generator {
70  if ($depth > 20) {
71  throw new \ilMDStructureException('LOM Structure is nested to deep.');
72  }
73  foreach ($readers as $reader) {
74  yield $this->structure_factory->structure(
75  $reader->definition(),
76  ...$this->getSubElements($depth + 1, ...$reader->subDefinitions())
77  );
78  }
79  }
80 }
getSubElements(int $depth, ReaderInterface ... $readers)
__construct(ReaderFactoryInterface $reader_factory, StructureFactory $structure_factory)