1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Ray\Di; |
||
6 | |||
7 | use Ray\Aop\Compiler; |
||
8 | |||
9 | use function array_shift; |
||
10 | |||
11 | /** |
||
12 | * @psalm-import-type ModuleList from Types |
||
13 | */ |
||
14 | final class ContainerFactory |
||
15 | { |
||
16 | /** |
||
17 | * @param AbstractModule|ModuleList|null $module Module(s) |
||
18 | * @param non-empty-string $classDir |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
19 | */ |
||
20 | public function __invoke($module, string $classDir): Container |
||
21 | { |
||
22 | $oneModule = $this->getModule($module); |
||
23 | // install built-in module |
||
24 | $appModule = (new BuiltinModule())($oneModule); |
||
25 | $container = $appModule->getContainer(); |
||
26 | // Compile null objects |
||
27 | (new CompileNullObject())($container, $classDir); |
||
28 | // Compile aspects |
||
29 | $container->weaveAspects(new Compiler($classDir)); |
||
30 | |||
31 | return $container; |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @param AbstractModule|ModuleList|null $module Module(s) |
||
0 ignored issues
–
show
The type
Ray\Di\ModuleList was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
36 | */ |
||
37 | private function getModule($module): AbstractModule |
||
38 | { |
||
39 | if ($module instanceof AbstractModule) { |
||
40 | return $module; |
||
41 | } |
||
42 | |||
43 | if ($module === null) { |
||
0 ignored issues
–
show
|
|||
44 | return new NullModule(); |
||
45 | } |
||
46 | |||
47 | $modules = $module; |
||
48 | $oneModule = array_shift($modules); |
||
49 | foreach ($modules as $module) { |
||
0 ignored issues
–
show
|
|||
50 | $oneModule->install($module); |
||
51 | } |
||
52 | |||
53 | return $oneModule; |
||
54 | } |
||
55 | } |
||
56 |