ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
Manipulator.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
31 
33 {
37 
38  public function __construct(
39  BaseManipulator $base_manipulator,
40  NavigatorFactoryInterface $navigator_factory,
41  RepositoryInterface $repository
42  ) {
43  $this->base_manipulator = $base_manipulator;
44  $this->navigator_factory = $navigator_factory;
45  $this->repository = $repository;
46  }
47 
51  public function addScaffolds(
52  SetInterface $set,
53  ?PathInterface $path = null
54  ): SetInterface {
55  $set = clone $set;
56  $to_be_scaffolded = [];
57  foreach ($this->getElements($set, $path) as $el) {
58  $super = $el->getSuperElement() ?? $el;
59  if (!in_array($super, $to_be_scaffolded, true)) {
60  $to_be_scaffolded[] = $super;
61  }
62  }
63  while (!empty($to_be_scaffolded)) {
64  $next = [];
65  foreach ($to_be_scaffolded as $element) {
66  if (!($element instanceof ScaffoldableInterface)) {
67  continue;
68  }
69  $element->addScaffoldsToSubElements($this->repository->scaffolds());
70  $next = array_merge(
71  $next,
72  iterator_to_array($element->getSubElements())
73  );
74  }
75  $to_be_scaffolded = $next;
76  }
77  return $set;
78  }
79 
80  public function prepareCreateOrUpdate(SetInterface $set, PathInterface $path, string ...$values): SetInterface
81  {
82  return $this->base_manipulator->prepareCreateOrUpdate(
83  $set,
84  $path,
85  ...$values
86  );
87  }
88 
89  public function prepareForceCreate(SetInterface $set, PathInterface $path, string ...$values): SetInterface
90  {
91  return $this->base_manipulator->prepareForceCreate(
92  $set,
93  $path,
94  ...$values
95  );
96  }
97 
99  {
100  return $this->base_manipulator->prepareDelete($set, $path);
101  }
102 
103  public function execute(SetInterface $set): void
104  {
105  $this->base_manipulator->execute($set);
106  }
107 
112  protected function getElements(
113  SetInterface $set,
114  ?PathInterface $path = null
115  ): \Generator {
116  if (!isset($path)) {
117  yield $set->getRoot();
118  return;
119  }
120  yield from $this->navigator_factory->navigator(
121  $path,
122  $set->getRoot()
123  )->elementsAtFinalStep();
124  }
125 }
__construct(BaseManipulator $base_manipulator, NavigatorFactoryInterface $navigator_factory, RepositoryInterface $repository)
Definition: Manipulator.php:38
getElements(SetInterface $set, ?PathInterface $path=null)
prepareCreateOrUpdate(SetInterface $set, PathInterface $path, string ... $values)
Follows the path, adding scaffolds where necessary to perform the step.
Definition: Manipulator.php:80
$path
Definition: ltiservices.php:32
getRoot()
Returns the root element of the metadata set.
prepareForceCreate(SetInterface $set, PathInterface $path, string ... $values)
Definition: Manipulator.php:89
prepareDelete(SetInterface $set, PathInterface $path)
Definition: Manipulator.php:98
NavigatorFactoryInterface $navigator_factory
Definition: Manipulator.php:35
addScaffolds(SetInterface $set, ?PathInterface $path=null)
Definition: Manipulator.php:51