1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the Micro framework package. |
||
5 | * |
||
6 | * (c) Stanislau Komar <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace Micro\Framework\Kernel; |
||
13 | |||
14 | use Micro\Component\DependencyInjection\Container; |
||
15 | use Micro\Framework\Kernel\Plugin\PluginBootLoaderInterface; |
||
16 | use Psr\Container\ContainerInterface; |
||
17 | |||
18 | class KernelBuilder |
||
19 | { |
||
20 | /** |
||
21 | * @var class-string[] |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
22 | */ |
||
23 | private array $pluginCollection; |
||
24 | |||
25 | /** |
||
26 | * @var PluginBootLoaderInterface[] |
||
27 | */ |
||
28 | private array $bootLoaderPluginCollection; |
||
29 | |||
30 | private ?Container $container; |
||
31 | |||
32 | public function __construct() |
||
33 | { |
||
34 | 3 | $this->pluginCollection = []; |
|
35 | 3 | $this->bootLoaderPluginCollection = []; |
|
36 | 3 | $this->container = null; |
|
37 | } |
||
38 | |||
39 | /** |
||
40 | * @param class-string[] $applicationPluginCollection |
||
0 ignored issues
–
show
|
|||
41 | * |
||
42 | * @return $this |
||
43 | */ |
||
44 | public function setApplicationPlugins(array $applicationPluginCollection): self |
||
45 | { |
||
46 | 3 | $this->pluginCollection = $applicationPluginCollection; |
|
47 | |||
48 | 3 | return $this; |
|
49 | } |
||
50 | |||
51 | /** |
||
52 | * @return $this |
||
53 | */ |
||
54 | public function addBootLoader(PluginBootLoaderInterface $bootLoader): self |
||
55 | { |
||
56 | 1 | $this->bootLoaderPluginCollection[] = $bootLoader; |
|
57 | |||
58 | 1 | return $this; |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * @param PluginBootLoaderInterface[] $bootLoaderCollection |
||
63 | * |
||
64 | * @return $this |
||
65 | */ |
||
66 | public function addBootLoaders(iterable $bootLoaderCollection): self |
||
67 | { |
||
68 | 1 | foreach ($bootLoaderCollection as $bootLoader) { |
|
69 | 1 | $this->addBootLoader($bootLoader); |
|
70 | } |
||
71 | |||
72 | 1 | return $this; |
|
73 | } |
||
74 | |||
75 | /** |
||
76 | * @param Container $container |
||
77 | * |
||
78 | * @return $this |
||
79 | */ |
||
80 | public function setContainer(ContainerInterface $container): self |
||
81 | { |
||
82 | 1 | $this->container = $container; |
|
83 | |||
84 | 1 | return $this; |
|
85 | } |
||
86 | |||
87 | protected function container(): Container |
||
88 | { |
||
89 | 3 | return $this->container ?? new Container(); |
|
90 | } |
||
91 | |||
92 | /** |
||
93 | * @return Kernel |
||
94 | */ |
||
95 | public function build(): KernelInterface |
||
96 | { |
||
97 | 3 | return new Kernel( |
|
98 | 3 | $this->pluginCollection, |
|
99 | 3 | $this->bootLoaderPluginCollection, |
|
100 | 3 | $this->container(), |
|
101 | 3 | ); |
|
102 | } |
||
103 | } |
||
104 |