ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
OfComponent.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 
25 class OfComponent implements \ArrayAccess
26 {
27  protected Component $component;
28  protected array $dependencies = [];
29 
30  public function __construct(Component $component, Dependency ...$ds)
31  {
32  $this->component = $component;
33 
34  foreach ($ds as $d) {
35  if (!isset($this->dependencies[(string) $d])) {
36  $this->dependencies[(string) $d] = [];
37  }
38  $this->dependencies[(string) $d][] = $d;
39  if ($d instanceof Out) {
40  $d->setComponent($this);
41  }
42  }
43  }
44 
45  public function getComponent(): Component
46  {
47  return $this->component;
48  }
49 
50  public function getComponentName(): string
51  {
52  return get_class($this->getComponent());
53  }
54 
55  public function getInDependencies(): \Iterator
56  {
57  foreach ($this->dependencies as $d) {
58  foreach ($d as $i) {
59  if ($i instanceof In) {
60  yield $i;
61  }
62  }
63  }
64  }
65 
66  public function getInDependenciesOf(InType $type): \Iterator
67  {
68  foreach ($this->dependencies as $d) {
69  foreach ($d as $i) {
70  if ($i instanceof In && $i->getType() === $type) {
71  yield $i;
72  }
73  }
74  }
75  }
76 
77  public function getOutDependenciesOf(OutType $type): \Iterator
78  {
79  foreach ($this->dependencies as $d) {
80  foreach ($d as $o) {
81  if ($o instanceof Out && $o->getType() === $type) {
82  yield $o;
83  }
84  }
85  }
86  }
87 
88  public function resetResolutions(): void
89  {
90  foreach ($this->dependencies as $d) {
91  foreach ($d as $o) {
92  $o->resetResolutions();
93  }
94  }
95  }
96 
97  // ArrayAccess
98 
99  public function offsetExists($dependency_description): bool
100  {
101  return array_key_exists($dependency_description, $this->dependencies);
102  }
103 
104  public function offsetGet($dependency_description): ?array
105  {
106  return $this->dependencies[$dependency_description];
107  }
108 
109  public function offsetSet($offset, $value): void
110  {
111  throw new \LogicException(
112  "Cannot modify dependencies of component."
113  );
114  }
115 
116  public function offsetUnset($offset): void
117  {
118  throw new \LogicException(
119  "Cannot modify dependencies of component."
120  );
121  }
122 }
offsetGet($dependency_description)
offsetExists($dependency_description)
Definition: OfComponent.php:99
__construct(Component $component, Dependency ... $ds)
Definition: OfComponent.php:30
A dependency where the component needs something from the world.
Definition: In.php:26
A dependency where the component gives something to the world.
Definition: Out.php:26