|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: afshin |
|
5
|
|
|
* Date: 12/12/17 |
|
6
|
|
|
* Time: 5:30 PM |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Core; |
|
10
|
|
|
use Composer\Autoload\ClassLoader; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* This will load modules |
|
15
|
|
|
*/ |
|
16
|
|
|
class ModuleInitializer |
|
17
|
|
|
{ |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var Slim |
|
|
|
|
|
|
21
|
|
|
*/ |
|
22
|
|
|
protected $app; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var array |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $initializerSettings; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var array |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $moduleInstances = []; |
|
33
|
|
|
|
|
34
|
|
|
public function __construct($app, $modules=array()) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->app = $app; |
|
37
|
|
|
// build an class map of [[module => moduleClassPath], ..] |
|
38
|
|
|
foreach ($modules as $module) { |
|
39
|
|
|
$moduleClassName = sprintf('%s\Module', $module); |
|
40
|
|
|
|
|
41
|
|
|
$this->moduleInstances[$module] = new $moduleClassName(); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Load the module. This will run for all modules, use for routes mainly |
|
47
|
|
|
* @param string $moduleName Module name |
|
48
|
|
|
*/ |
|
49
|
|
|
public function initModules() |
|
50
|
|
|
{ |
|
51
|
|
|
$moduleInstances = $this->moduleInstances; |
|
|
|
|
|
|
52
|
|
|
$app = $this->app; |
|
53
|
|
|
$container = $app->getContainer(); |
|
54
|
|
|
|
|
55
|
|
|
// $this->initClassLoader($classLoader); |
|
56
|
|
|
$this->initModuleConfig(); |
|
57
|
|
|
$this->initDependencies($container); |
|
|
|
|
|
|
58
|
|
|
$this->initMiddleware($app); |
|
|
|
|
|
|
59
|
|
|
$this->initRoutes($app); |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Load the module. This will run for all modules, use for routes mainly |
|
65
|
|
|
* @param string $moduleName Module name |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getModuleConfig() |
|
68
|
|
|
{ |
|
69
|
|
|
$moduleInstances = $this->moduleInstances; |
|
70
|
|
|
|
|
71
|
|
|
$allModules = []; |
|
72
|
|
|
foreach ($moduleInstances as $moduleName => $module) { |
|
73
|
|
|
$moduleSettings = $module->getModuleConfig(); |
|
|
|
|
|
|
74
|
|
|
$allModules[$moduleName] = $module->getModuleConfig(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return $allModules; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Load the module. This will run for all modules, use for routes mainly |
|
82
|
|
|
* @param string $moduleName Module name |
|
83
|
|
|
*/ |
|
84
|
|
|
public function initModuleConfig() |
|
85
|
|
|
{ |
|
86
|
|
|
$app = $this->app; |
|
87
|
|
|
$container = $app->getContainer(); |
|
88
|
|
|
|
|
89
|
|
|
$allSettings = $container['settings']->all(); |
|
90
|
|
|
if (!isset($allSettings['modules']) or !is_array($allSettings['modules'])) { |
|
91
|
|
|
$allSettings['modules'] = []; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
$allSettings['modules'] = array_merge_recursive($allSettings['modules'], $this->getModuleConfig()); |
|
95
|
|
|
$container['settings']->__construct( $allSettings ); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Load the module. This will run for all modules, use for routes mainly |
|
100
|
|
|
* @param string $moduleName Module name |
|
101
|
|
|
*/ |
|
102
|
|
|
public function initDependencies() |
|
103
|
|
|
{ |
|
104
|
|
|
$moduleInstances = $this->moduleInstances; |
|
105
|
|
|
$app = $this->app; |
|
106
|
|
|
$container = $app->getContainer(); |
|
107
|
|
|
|
|
108
|
|
|
// next, init dependencies of all modules now that we have settings, class maps etc |
|
109
|
|
|
foreach ($moduleInstances as $module) { |
|
110
|
|
|
$module->initDependencies($container); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Load the module. This will run for all modules, use for routes mainly |
|
116
|
|
|
* @param string $moduleName Module name |
|
117
|
|
|
*/ |
|
118
|
|
|
public function initMiddleware() |
|
119
|
|
|
{ |
|
120
|
|
|
$moduleInstances = $this->moduleInstances; |
|
121
|
|
|
$app = $this->app; |
|
122
|
|
|
|
|
123
|
|
|
// next, init app middleware of all modules now that we have settings, class maps, dependencies etc |
|
124
|
|
|
foreach ($moduleInstances as $module) { |
|
125
|
|
|
$module->initMiddleware($app); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Load the module. This will run for all modules, use for routes mainly |
|
131
|
|
|
* @param string $moduleName Module name |
|
132
|
|
|
*/ |
|
133
|
|
|
public function initRoutes() |
|
134
|
|
|
{ |
|
135
|
|
|
$moduleInstances = $this->moduleInstances; |
|
136
|
|
|
$app = $this->app; |
|
137
|
|
|
|
|
138
|
|
|
// lastly, routes |
|
139
|
|
|
foreach ($moduleInstances as $module) { |
|
140
|
|
|
$module->initRoutes($app); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
|
|
146
|
|
|
|
|
147
|
|
|
|
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.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths