ILIAS  trunk Revision v11.0_alpha-1831-g8615d53dadb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ILIAS\Component\Dependencies\Reader Class Reference
+ Collaboration diagram for ILIAS\Component\Dependencies\Reader:

Public Member Functions

 read (Component $component)
 

Protected Member Functions

 addDefine ($_, $name)
 
 addImplement (int $i, string $name, $value)
 
 cacheImplement (string $name, $value)
 
 addUse (string $name)
 
 addContribute (int $i, string $name, $value)
 
 cacheContribute (string $name, $value)
 
 addSeek (string $name)
 
 addProvide (int $i, string $name, $value)
 
 cacheProvide (string $name, $value)
 
 addPull (string $name)
 
 addInternalOut (string $name, $value)
 
 cacheInternalOut (string $name, $value)
 
 resolveInternalOut (string $name)
 
 addInternalIn (string $name)
 
 populateTempArrays ()
 
 flushTempArrays ()
 
 resolveDependencies ()
 
 compileResult (Component $component)
 
 createMock (string $class_name)
 

Protected Attributes

array $defines
 
array $implements
 
array $uses
 
array $uses_temp = []
 
array $contributes
 
array $seeks
 
array $seeks_temp = []
 
array $provides
 
array $pulls
 
array $pulls_temp = []
 
array $internal_out
 
array $internal_in
 
array $internal_in_temp = []
 

Detailed Description

Definition at line 25 of file Reader.php.

Member Function Documentation

◆ addContribute()

ILIAS\Component\Dependencies\Reader::addContribute ( int  $i,
string  $name,
  $value 
)
protected

Definition at line 133 of file Reader.php.

References Vendor\Package\$d, ILIAS\Component\Dependencies\Reader\flushTempArrays(), and ILIAS\Component\Dependencies\Reader\populateTempArrays().

Referenced by ILIAS\Component\Dependencies\Reader\resolveDependencies().

134  {
135  if (!is_callable($value)) {
136  throw new \LogicException(
137  "\$implements must be set with a callable."
138  );
139  }
140 
141  $this->populateTempArrays();
142  $impl = $value();
143  $dependencies = $this->flushTempArrays();
144 
145  if (!$impl instanceof $name) {
146  throw new \LogicException(
147  "Contribution for $name does not implement the correct interface."
148  );
149  }
150 
151  $aux = [
152  "position" => $i
153  ];
154  if ($impl instanceof \ILIAS\Component\EntryPoint) {
155  $aux["entry_point_name"] = $impl->getName();
156  }
157  $d = new Out(OutType::CONTRIBUTE, $name, $aux, $dependencies);
158  $this->contributes[$i] = $d;
159  }
Interface Observer Contains several chained tasks and infos about them.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addDefine()

ILIAS\Component\Dependencies\Reader::addDefine (   $_,
  $name 
)
protected

Definition at line 72 of file Reader.php.

References Vendor\Package\$d.

Referenced by ILIAS\Component\Dependencies\Reader\read().

73  {
74  if (!is_string($name) || !interface_exists($name)) {
75  throw new \LogicException(
76  "Only push interface-names into \$define."
77  );
78  }
79  $d = new Define(new Name($name));
80  $this->defines[] = $d;
81  }
+ Here is the caller graph for this function:

◆ addImplement()

ILIAS\Component\Dependencies\Reader::addImplement ( int  $i,
string  $name,
  $value 
)
protected

Definition at line 83 of file Reader.php.

References Vendor\Package\$d, ILIAS\Component\Dependencies\Reader\flushTempArrays(), and ILIAS\Component\Dependencies\Reader\populateTempArrays().

Referenced by ILIAS\Component\Dependencies\Reader\resolveDependencies().

84  {
85  if (!is_callable($value)) {
86  throw new \LogicException(
87  "\$implements must be set with a callable."
88  );
89  }
90 
91  $this->populateTempArrays();
92  $impl = $value();
93  $dependencies = $this->flushTempArrays();
94 
95  if (!$impl instanceof $name) {
96  throw new \LogicException(
97  "Implementation for $name does not implement the correct interface."
98  );
99  }
100 
101  $aux = [
102  "class" => get_class($impl),
103  "position" => $i
104  ];
105  $d = new Out(OutType::IMPLEMENT, $name, $aux, $dependencies);
106  $this->implements[$i] = $d;
107  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addInternalIn()

ILIAS\Component\Dependencies\Reader::addInternalIn ( string  $name)
protected

Definition at line 267 of file Reader.php.

References Vendor\Package\$d, ILIAS\Component\Dependencies\INTERNAL, and ILIAS\Component\Dependencies\Reader\resolveInternalOut().

Referenced by ILIAS\Component\Dependencies\Reader\read().

268  {
269  if (is_null($this->internal_in_temp)) {
270  throw new \LogicException(
271  "getting from \$internal is only allowed when defining other dependencies"
272  );
273  }
274 
275  if (array_key_exists($name, $this->internal_in)) {
276  $d = $this->internal_in[$name];
277  } else {
278  $d = new In(InType::INTERNAL, $name);
279  }
280 
281  $this->internal_in_temp[0][$name] = $d;
282 
283  $this->resolveInternalOut($name);
284 
285  return $this->internal_out[$name][1];
286  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addInternalOut()

ILIAS\Component\Dependencies\Reader::addInternalOut ( string  $name,
  $value 
)
protected

Definition at line 231 of file Reader.php.

References Vendor\Package\$d, ILIAS\Component\Dependencies\Reader\flushTempArrays(), ILIAS\Component\Dependencies\INTERNAL, null, and ILIAS\Component\Dependencies\Reader\populateTempArrays().

Referenced by ILIAS\Component\Dependencies\Reader\resolveInternalOut().

232  {
233  if (!is_callable($value)) {
234  throw new \LogicException(
235  "\$internal must be set with a callable."
236  );
237  }
238 
239  $this->populateTempArrays();
240  $impl = $value();
241  $dependencies = $this->flushTempArrays();
242 
243  $d = new Out(OutType::INTERNAL, $name, null, $dependencies);
244  $this->internal_out[$name] = [$d, $impl];
245  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addProvide()

ILIAS\Component\Dependencies\Reader::addProvide ( int  $i,
string  $name,
  $value 
)
protected

Definition at line 185 of file Reader.php.

References Vendor\Package\$d, ILIAS\Component\Dependencies\Reader\flushTempArrays(), null, and ILIAS\Component\Dependencies\Reader\populateTempArrays().

Referenced by ILIAS\Component\Dependencies\Reader\resolveDependencies().

186  {
187  if (!is_callable($value)) {
188  throw new \LogicException(
189  "\$implements must be set with a callable."
190  );
191  }
192 
193  $this->populateTempArrays();
194  $impl = $value();
195  $dependencies = $this->flushTempArrays();
196 
197  if (!$impl instanceof $name) {
198  throw new \LogicException(
199  "Provision for $name does not implement the correct interface."
200  );
201  }
202 
203  $d = new Out(OutType::PROVIDE, $name, null, $dependencies);
204  $this->provides[$i] = $d;
205  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addPull()

ILIAS\Component\Dependencies\Reader::addPull ( string  $name)
protected

Definition at line 212 of file Reader.php.

References Vendor\Package\$d, and ILIAS\Component\Dependencies\Reader\createMock().

Referenced by ILIAS\Component\Dependencies\Reader\read().

213  {
214  if (empty($this->pulls_temp)) {
215  throw new \LogicException(
216  "\$pull is only allowed when defining other dependencies"
217  );
218  }
219 
220  if (array_key_exists($name, $this->pulls)) {
221  $d = $this->pulls[$name];
222  } else {
223  $d = new In(InType::PULL, $name);
224  }
225 
226  $this->pulls_temp[0][$name] = $d;
227 
228  return $this->createMock($name);
229  }
createMock(string $class_name)
Definition: Reader.php:353
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addSeek()

ILIAS\Component\Dependencies\Reader::addSeek ( string  $name)
protected

Definition at line 166 of file Reader.php.

References Vendor\Package\$d.

Referenced by ILIAS\Component\Dependencies\Reader\read().

167  {
168  if (empty($this->seeks_temp)) {
169  throw new \LogicException(
170  "\$seek is only allowed when defining other dependencies"
171  );
172  }
173 
174  if (array_key_exists($name, $this->seeks)) {
175  $d = $this->seeks[$name];
176  } else {
177  $d = new In(InType::SEEK, $name);
178  }
179 
180  $this->seeks_temp[0][$name] = $d;
181 
182  return [];
183  }
+ Here is the caller graph for this function:

◆ addUse()

ILIAS\Component\Dependencies\Reader::addUse ( string  $name)
protected

Definition at line 114 of file Reader.php.

References Vendor\Package\$d, and ILIAS\Component\Dependencies\Reader\createMock().

Referenced by ILIAS\Component\Dependencies\Reader\read().

115  {
116  if (empty($this->uses_temp)) {
117  throw new \LogicException(
118  "\$use is only allowed when defining other dependencies"
119  );
120  }
121 
122  if (array_key_exists($name, $this->uses)) {
123  $d = $this->uses[$name];
124  } else {
125  $d = new In(InType::USE, $name);
126  }
127 
128  $this->uses_temp[0][$name] = $d;
129 
130  return $this->createMock($name);
131  }
createMock(string $class_name)
Definition: Reader.php:353
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cacheContribute()

ILIAS\Component\Dependencies\Reader::cacheContribute ( string  $name,
  $value 
)
protected

Definition at line 161 of file Reader.php.

Referenced by ILIAS\Component\Dependencies\Reader\read().

162  {
163  $this->contributes[] = [$name, $value];
164  }
+ Here is the caller graph for this function:

◆ cacheImplement()

ILIAS\Component\Dependencies\Reader::cacheImplement ( string  $name,
  $value 
)
protected

Definition at line 109 of file Reader.php.

Referenced by ILIAS\Component\Dependencies\Reader\read().

110  {
111  $this->implements[] = [$name, $value];
112  }
+ Here is the caller graph for this function:

◆ cacheInternalOut()

ILIAS\Component\Dependencies\Reader::cacheInternalOut ( string  $name,
  $value 
)
protected

Definition at line 247 of file Reader.php.

Referenced by ILIAS\Component\Dependencies\Reader\read().

248  {
249  $this->internal_out[$name] = [$name, $value];
250  }
+ Here is the caller graph for this function:

◆ cacheProvide()

ILIAS\Component\Dependencies\Reader::cacheProvide ( string  $name,
  $value 
)
protected

Definition at line 207 of file Reader.php.

Referenced by ILIAS\Component\Dependencies\Reader\read().

208  {
209  $this->provides[] = [$name, $value];
210  }
+ Here is the caller graph for this function:

◆ compileResult()

ILIAS\Component\Dependencies\Reader::compileResult ( Component  $component)
protected

Definition at line 330 of file Reader.php.

References Vendor\Package\$a.

Referenced by ILIAS\Component\Dependencies\Reader\read().

330  : OfComponent
331  {
332  return new OfComponent(
333  $component,
334  ...array_merge(
335  ...array_map(
336  "array_values",
337  [
338  $this->defines,
339  $this->implements,
340  $this->uses,
341  $this->contributes,
342  $this->seeks,
343  $this->provides,
344  $this->pulls,
345  array_map(fn($a) => $a[0], $this->internal_out),
346  $this->internal_in
347  ]
348  )
349  )
350  );
351  }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ Here is the caller graph for this function:

◆ createMock()

ILIAS\Component\Dependencies\Reader::createMock ( string  $class_name)
protected

Definition at line 353 of file Reader.php.

Referenced by ILIAS\Component\Dependencies\Reader\addPull(), and ILIAS\Component\Dependencies\Reader\addUse().

353  : object
354  {
355  $mock_builder = new \PHPUnit\Framework\MockObject\MockBuilder(new class ('dummy') extends \PHPUnit\Framework\TestCase {
356  public function dummy()
357  {
358  }
359  }, $class_name);
360  return $mock_builder
361  ->disableOriginalConstructor()
362  ->disableOriginalClone()
363  ->disableArgumentCloning()
364  ->disallowMockingUnknownTypes()
365  ->getMock();
366  }
+ Here is the caller graph for this function:

◆ flushTempArrays()

ILIAS\Component\Dependencies\Reader::flushTempArrays ( )
protected

Definition at line 296 of file Reader.php.

Referenced by ILIAS\Component\Dependencies\Reader\addContribute(), ILIAS\Component\Dependencies\Reader\addImplement(), ILIAS\Component\Dependencies\Reader\addInternalOut(), and ILIAS\Component\Dependencies\Reader\addProvide().

296  : array
297  {
298  $uses_temp = array_shift($this->uses_temp);
299  $seeks_temp = array_shift($this->seeks_temp);
300  $pulls_temp = array_shift($this->pulls_temp);
301  $internal_in_temp = array_shift($this->internal_in_temp);
302 
303 
304  $this->uses = array_merge($this->uses, $uses_temp);
305  $this->seeks = array_merge($this->seeks, $seeks_temp);
306  $this->pulls = array_merge($this->pulls, $pulls_temp);
307  $this->internal_in = array_merge($this->internal_in, $internal_in_temp);
308 
309  $dependencies = array_merge(...array_map("array_values", [$uses_temp, $seeks_temp, $pulls_temp, $internal_in_temp]));
310 
311  return $dependencies;
312  }
+ Here is the caller graph for this function:

◆ populateTempArrays()

ILIAS\Component\Dependencies\Reader::populateTempArrays ( )
protected

Definition at line 288 of file Reader.php.

Referenced by ILIAS\Component\Dependencies\Reader\addContribute(), ILIAS\Component\Dependencies\Reader\addImplement(), ILIAS\Component\Dependencies\Reader\addInternalOut(), and ILIAS\Component\Dependencies\Reader\addProvide().

288  : void
289  {
290  array_unshift($this->uses_temp, []);
291  array_unshift($this->seeks_temp, []);
292  array_unshift($this->pulls_temp, []);
293  array_unshift($this->internal_in_temp, []);
294  }
+ Here is the caller graph for this function:

◆ read()

ILIAS\Component\Dependencies\Reader::read ( Component  $component)
Returns
Dependency[]

Definition at line 44 of file Reader.php.

References ILIAS\Component\Dependencies\Reader\addDefine(), ILIAS\Component\Dependencies\Reader\addInternalIn(), ILIAS\Component\Dependencies\Reader\addPull(), ILIAS\Component\Dependencies\Reader\addSeek(), ILIAS\Component\Dependencies\Reader\addUse(), ILIAS\Component\Dependencies\Reader\cacheContribute(), ILIAS\Component\Dependencies\Reader\cacheImplement(), ILIAS\Component\Dependencies\Reader\cacheInternalOut(), ILIAS\Component\Dependencies\Reader\cacheProvide(), ILIAS\Component\Dependencies\Reader\compileResult(), ILIAS\Component\Component\init(), and ILIAS\Component\Dependencies\Reader\resolveDependencies().

44  : OfComponent
45  {
46  $this->defines = [];
47  $this->implements = [];
48  $this->uses = [];
49  $this->contributes = [];
50  $this->seeks = [];
51  $this->provides = [];
52  $this->pulls = [];
53  $this->internal_out = [];
54  $this->internal_in = [];
55 
56  $probes = [
57  new SetProbe(fn($n, $v) => $this->addDefine($n, $v)),
58  new SetProbe(fn($n, $v) => $this->cacheImplement($n, $v)),
59  new GetProbe(fn($n) => $this->addUse($n)),
60  new SetProbe(fn($n, $v) => $this->cacheContribute($n, $v)),
61  new GetProbe(fn($n) => $this->addSeek($n)),
62  new SetProbe(fn($n, $v) => $this->cacheProvide($n, $v)),
63  new GetProbe(fn($n) => $this->addPull($n)),
64  new SetGetProbe(fn($n, $v) => $this->cacheInternalOut($n, $v), fn($n) => $this->addInternalIn($n))
65  ];
66  $component->init(...$probes);
67 
68  $this->resolveDependencies();
69  return $this->compileResult($component);
70  }
cacheInternalOut(string $name, $value)
Definition: Reader.php:247
cacheProvide(string $name, $value)
Definition: Reader.php:207
compileResult(Component $component)
Definition: Reader.php:330
cacheContribute(string $name, $value)
Definition: Reader.php:161
cacheImplement(string $name, $value)
Definition: Reader.php:109
+ Here is the call graph for this function:

◆ resolveDependencies()

ILIAS\Component\Dependencies\Reader::resolveDependencies ( )
protected

Definition at line 314 of file Reader.php.

References ILIAS\Component\Dependencies\Reader\addContribute(), ILIAS\Component\Dependencies\Reader\addImplement(), ILIAS\Component\Dependencies\Reader\addProvide(), and ILIAS\Component\Dependencies\Reader\resolveInternalOut().

Referenced by ILIAS\Component\Dependencies\Reader\read().

314  : void
315  {
316  foreach ($this->implements as $i => $v) {
317  $this->addImplement($i, ...$v);
318  }
319  foreach ($this->contributes as $i => $v) {
320  $this->addContribute($i, ...$v);
321  }
322  foreach ($this->provides as $i => $v) {
323  $this->addProvide($i, ...$v);
324  }
325  foreach (array_keys($this->internal_out) as $i) {
326  $this->resolveInternalOut($i);
327  }
328  }
addProvide(int $i, string $name, $value)
Definition: Reader.php:185
addContribute(int $i, string $name, $value)
Definition: Reader.php:133
addImplement(int $i, string $name, $value)
Definition: Reader.php:83
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resolveInternalOut()

ILIAS\Component\Dependencies\Reader::resolveInternalOut ( string  $name)
protected

Definition at line 252 of file Reader.php.

References ILIAS\Component\Dependencies\Reader\addInternalOut().

Referenced by ILIAS\Component\Dependencies\Reader\addInternalIn(), and ILIAS\Component\Dependencies\Reader\resolveDependencies().

253  {
254  if (!array_key_exists($name, $this->internal_out)) {
255  throw new \LogicException(
256  "Cannot resolve dependency \$internal[$name]. It either does not exist or is defined circular."
257  );
258  }
259 
260  if (!$this->internal_out[$name][0] instanceof Out) {
261  $values = $this->internal_out[$name];
262  unset($this->internal_out[$name]);
263  $this->addInternalOut(...$values);
264  }
265  }
addInternalOut(string $name, $value)
Definition: Reader.php:231
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $contributes

array ILIAS\Component\Dependencies\Reader::$contributes
protected

Definition at line 31 of file Reader.php.

◆ $defines

array ILIAS\Component\Dependencies\Reader::$defines
protected

Definition at line 27 of file Reader.php.

◆ $implements

array ILIAS\Component\Dependencies\Reader::$implements
protected

Definition at line 28 of file Reader.php.

◆ $internal_in

array ILIAS\Component\Dependencies\Reader::$internal_in
protected

Definition at line 38 of file Reader.php.

◆ $internal_in_temp

array ILIAS\Component\Dependencies\Reader::$internal_in_temp = []
protected

Definition at line 39 of file Reader.php.

◆ $internal_out

array ILIAS\Component\Dependencies\Reader::$internal_out
protected

Definition at line 37 of file Reader.php.

◆ $provides

array ILIAS\Component\Dependencies\Reader::$provides
protected

Definition at line 34 of file Reader.php.

◆ $pulls

array ILIAS\Component\Dependencies\Reader::$pulls
protected

Definition at line 35 of file Reader.php.

◆ $pulls_temp

array ILIAS\Component\Dependencies\Reader::$pulls_temp = []
protected

Definition at line 36 of file Reader.php.

◆ $seeks

array ILIAS\Component\Dependencies\Reader::$seeks
protected

Definition at line 32 of file Reader.php.

◆ $seeks_temp

array ILIAS\Component\Dependencies\Reader::$seeks_temp = []
protected

Definition at line 33 of file Reader.php.

◆ $uses

array ILIAS\Component\Dependencies\Reader::$uses
protected

Definition at line 29 of file Reader.php.

◆ $uses_temp

array ILIAS\Component\Dependencies\Reader::$uses_temp = []
protected

Definition at line 30 of file Reader.php.


The documentation for this class was generated from the following file: