2
2
3
3
namespace DI \Kernel ;
4
4
5
+ use ComposerLocator ;
5
6
use DI \Cache \ArrayCache ;
6
7
use DI \Container ;
7
8
use DI \ContainerBuilder ;
8
9
use Doctrine \Common \Cache \Cache ;
9
- use Interop \Container \ContainerInterface ;
10
- use Puli \Discovery \Api \Discovery ;
11
- use Puli \Repository \Api \Resource \FilesystemResource ;
12
- use Puli \Repository \Api \ResourceRepository ;
13
10
14
11
/**
15
12
* Application kernel.
19
16
class Kernel
20
17
{
21
18
/**
22
- * If null, defaults to the constant PULI_FACTORY_CLASS defined by Puli.
23
- *
24
- * @var string|null
19
+ * @var string
25
20
*/
26
- public static $ puliFactoryClass ;
21
+ public static $ locatorClass = ' ComposerLocator ' ;
27
22
28
23
/**
29
24
* @var string[]
@@ -44,7 +39,7 @@ class Kernel
44
39
* @param array $modules The name of the modules to load.
45
40
* @param string $environment Environment of the application (prod, dev, test, ...).
46
41
*/
47
- public function __construct (array $ modules = [], $ environment = 'prod ' )
42
+ public function __construct (array $ modules = [], string $ environment = 'prod ' )
48
43
{
49
44
$ this ->modules = $ modules ;
50
45
$ this ->environment = $ environment ;
@@ -65,43 +60,19 @@ public function addConfig(array $config)
65
60
}
66
61
67
62
/**
68
- * Configure and create a container using all configuration files registered under
69
- * the `php-di/configuration` binding type in Puli.
70
- *
71
- * @return Container
63
+ * Configure and create a container using all configuration files found in included modules.
72
64
*/
73
- public function createContainer ()
65
+ public function createContainer () : Container
74
66
{
75
- if (!self ::$ puliFactoryClass && !defined ('PULI_FACTORY_CLASS ' )) {
76
- throw new \RuntimeException ('Puli is not installed ' );
77
- }
78
-
79
- // Create Puli objects
80
- $ factoryClass = self ::$ puliFactoryClass ?: PULI_FACTORY_CLASS ;
81
- $ puli = new $ factoryClass ();
82
- /** @var ResourceRepository $repository */
83
- $ repository = $ puli ->createRepository ();
84
-
85
67
$ containerBuilder = new ContainerBuilder ();
86
68
87
69
$ cache = $ this ->getContainerCache ();
88
70
if ($ cache ) {
89
71
$ containerBuilder ->setDefinitionCache ($ cache );
90
72
}
91
73
92
- // Puli objects
93
- $ containerBuilder ->addDefinitions ([
94
- 'puli.factory ' => $ puli ,
95
- ResourceRepository::class => $ repository ,
96
- Discovery::class => function (ContainerInterface $ c ) {
97
- $ puli = $ c ->get ('puli.factory ' );
98
-
99
- return $ puli ->createDiscovery ($ c ->get (ResourceRepository::class));
100
- },
101
- ]);
102
-
103
74
foreach ($ this ->modules as $ module ) {
104
- $ this ->loadModule ($ containerBuilder , $ repository , $ module );
75
+ $ this ->loadModule ($ containerBuilder , $ module );
105
76
}
106
77
107
78
if (!empty ($ this ->config )) {
@@ -130,22 +101,20 @@ protected function configureContainerBuilder(ContainerBuilder $containerBuilder)
130
101
{
131
102
}
132
103
133
- private function loadModule (ContainerBuilder $ builder , ResourceRepository $ resources , $ module )
104
+ private function loadModule (ContainerBuilder $ builder , string $ module )
134
105
{
106
+ $ locatorClass = self ::$ locatorClass ;
107
+ $ path = $ locatorClass ::getPath ($ module );
108
+
135
109
// Load all config files in the config/ directory
136
- foreach ($ resources ->find ('/ ' .$ module .'/config/*.php ' ) as $ resource ) {
137
- if ($ resource instanceof FilesystemResource) {
138
- $ builder ->addDefinitions ($ resource ->getFilesystemPath ());
139
- }
110
+ foreach (glob ($ path .'/res/config/*.php ' ) as $ file ) {
111
+ $ builder ->addDefinitions ($ file );
140
112
}
141
113
142
114
// Load the environment-specific config if it exists
143
- $ envConfig = '/ ' .$ module .'/config/env/ ' .$ this ->environment .'.php ' ;
144
- if ($ resources ->contains ($ envConfig )) {
145
- $ resource = $ resources ->get ($ envConfig );
146
- if ($ resource instanceof FilesystemResource) {
147
- $ builder ->addDefinitions ($ resource ->getFilesystemPath ());
148
- }
115
+ $ envConfig = $ path .'/res/config/env/ ' .$ this ->environment .'.php ' ;
116
+ if (file_exists ($ envConfig )) {
117
+ $ builder ->addDefinitions ($ envConfig );
149
118
}
150
119
}
151
120
}
0 commit comments