19 declare(strict_types=1);
47 $this->implements = [];
49 $this->contributes = [];
53 $this->internal_out = [];
54 $this->internal_in = [];
66 $component->
init(...$probes);
74 if (!is_string($name) || !interface_exists($name)) {
75 throw new \LogicException(
76 "Only push interface-names into \$define." 80 $this->defines[] =
$d;
85 if (!is_callable($value)) {
86 throw new \LogicException(
87 "\$implements must be set with a callable." 95 if (!$impl instanceof $name) {
96 throw new \LogicException(
97 "Implementation for $name does not implement the correct interface." 102 "class" => get_class($impl),
105 $d =
new Out(OutType::IMPLEMENT, $name, $aux, $dependencies);
106 $this->implements[$i] =
$d;
111 $this->implements[] = [$name, $value];
116 if (empty($this->uses_temp)) {
117 throw new \LogicException(
118 "\$use is only allowed when defining other dependencies" 122 if (array_key_exists($name, $this->uses)) {
123 $d = $this->uses[$name];
125 $d =
new In(InType::USE, $name);
128 $this->uses_temp[0][$name] =
$d;
135 if (!is_callable($value)) {
136 throw new \LogicException(
137 "\$implements must be set with a callable." 145 if (!$impl instanceof $name) {
146 throw new \LogicException(
147 "Contribution for $name does not implement the correct interface." 155 $aux[
"entry_point_name"] = $impl->getName();
157 $d =
new Out(OutType::CONTRIBUTE, $name, $aux, $dependencies);
158 $this->contributes[$i] =
$d;
163 $this->contributes[] = [$name, $value];
168 if (empty($this->seeks_temp)) {
169 throw new \LogicException(
170 "\$seek is only allowed when defining other dependencies" 174 if (array_key_exists($name, $this->seeks)) {
175 $d = $this->seeks[$name];
177 $d =
new In(InType::SEEK, $name);
180 $this->seeks_temp[0][$name] =
$d;
187 if (!is_callable($value)) {
188 throw new \LogicException(
189 "\$implements must be set with a callable." 197 if (!$impl instanceof $name) {
198 throw new \LogicException(
199 "Provision for $name does not implement the correct interface." 203 $d =
new Out(OutType::PROVIDE, $name,
null, $dependencies);
204 $this->provides[$i] =
$d;
209 $this->provides[] = [$name, $value];
214 if (empty($this->pulls_temp)) {
215 throw new \LogicException(
216 "\$pull is only allowed when defining other dependencies" 220 if (array_key_exists($name, $this->pulls)) {
221 $d = $this->pulls[$name];
223 $d =
new In(InType::PULL, $name);
226 $this->pulls_temp[0][$name] =
$d;
233 if (!is_callable($value)) {
234 throw new \LogicException(
235 "\$internal must be set with a callable." 244 $this->internal_out[$name] = [
$d, $impl];
249 $this->internal_out[$name] = [$name, $value];
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." 260 if (!$this->internal_out[$name][0] instanceof
Out) {
261 $values = $this->internal_out[$name];
262 unset($this->internal_out[$name]);
269 if (is_null($this->internal_in_temp)) {
270 throw new \LogicException(
271 "getting from \$internal is only allowed when defining other dependencies" 275 if (array_key_exists($name, $this->internal_in)) {
276 $d = $this->internal_in[$name];
281 $this->internal_in_temp[0][$name] =
$d;
285 return $this->internal_out[$name][1];
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, []);
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);
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);
309 $dependencies = array_merge(...
array_map(
"array_values", [$uses_temp, $seeks_temp, $pulls_temp, $internal_in_temp]));
311 return $dependencies;
316 foreach ($this->implements as $i => $v) {
319 foreach ($this->contributes as $i => $v) {
322 foreach ($this->provides as $i => $v) {
325 foreach (array_keys($this->internal_out) as $i) {
355 $mock_builder = new \PHPUnit\Framework\MockObject\MockBuilder(
new class (
'dummy') extends \
PHPUnit\Framework\TestCase {
356 public function dummy()
361 ->disableOriginalConstructor()
362 ->disableOriginalClone()
363 ->disableArgumentCloning()
364 ->disallowMockingUnknownTypes()
cacheInternalOut(string $name, $value)
init(array|\ArrayAccess &$define, array|\ArrayAccess &$implement, array|\ArrayAccess &$use, array|\ArrayAccess &$contribute, array|\ArrayAccess &$seek, array|\ArrayAccess &$provide, array|\ArrayAccess &$pull, array|\ArrayAccess &$internal,)
addInternalIn(string $name)
Interface Observer Contains several chained tasks and infos about them.
cacheProvide(string $name, $value)
createMock(string $class_name)
addProvide(int $i, string $name, $value)
compileResult(Component $component)
addInternalOut(string $name, $value)
addContribute(int $i, string $name, $value)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
cacheContribute(string $name, $value)
An entrypoint is where the programm execution starts.
A dependency where the component needs something from the world.
read(Component $component)
resolveInternalOut(string $name)
addImplement(int $i, string $name, $value)
cacheImplement(string $name, $value)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
A dependency where the component gives something to the world.