1 | <?php |
||
11 | class Module |
||
12 | { |
||
13 | /** |
||
14 | * @const ERR_FILE_NOT_FOUND Exception code if the file is not found. |
||
15 | */ |
||
16 | const ERR_FILE_NOT_FOUND = 1310001; |
||
17 | |||
18 | /** |
||
19 | * @const ERR_JSON_PARSE Exception code if the parse of a json file fail. |
||
20 | */ |
||
21 | const ERR_JSON_PARSE = 1310002; |
||
22 | |||
23 | /** |
||
24 | * @const ERR_RUNNER_FILE_NOT_FOUND Exception code if the runner file to |
||
25 | * execute is not found. |
||
26 | */ |
||
27 | const ERR_RUNNER_FILE_NOT_FOUND = 1310003; |
||
28 | |||
29 | /** |
||
30 | * @var string $pathName Module's name |
||
31 | */ |
||
32 | protected $pathName = ''; |
||
33 | |||
34 | /** |
||
35 | * @var \BFW\Config $config Config object for this module |
||
36 | */ |
||
37 | protected $config; |
||
38 | |||
39 | /** |
||
40 | * @var \stdClass $loadInfos All informations about how to run the module |
||
41 | */ |
||
42 | protected $loadInfos; |
||
43 | |||
44 | /** |
||
45 | * @var \stdClass $status Load and run status |
||
46 | */ |
||
47 | protected $status; |
||
48 | |||
49 | /** |
||
50 | * Constructor |
||
51 | * |
||
52 | * @param string $pathName Module name |
||
53 | */ |
||
54 | public function __construct($pathName) |
||
62 | |||
63 | /** |
||
64 | * Load informations about the module |
||
65 | * |
||
66 | * @return void |
||
67 | */ |
||
68 | public function loadModule() |
||
75 | |||
76 | /** |
||
77 | * Get installation informations |
||
78 | * |
||
79 | * @param string $sourceFiles Path to module source (in vendor) |
||
80 | * |
||
81 | * @return \stdClass |
||
82 | */ |
||
83 | public static function installInfos($sourceFiles) |
||
90 | |||
91 | /** |
||
92 | * Get the module's name |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | public function getPathName() |
||
100 | |||
101 | /** |
||
102 | * Get the Config object which have config for this module |
||
103 | * |
||
104 | * @return \BFW\Config |
||
105 | */ |
||
106 | public function getConfig() |
||
110 | |||
111 | /** |
||
112 | * Get the load informations |
||
113 | * |
||
114 | * @return \stdClass |
||
115 | */ |
||
116 | public function getLoadInfos() |
||
120 | |||
121 | /** |
||
122 | * Get the status object for this module |
||
123 | * |
||
124 | * @return \stdClass |
||
125 | */ |
||
126 | public function getStatus() |
||
130 | |||
131 | /** |
||
132 | * Return the load status |
||
133 | * |
||
134 | * @return boolean |
||
135 | */ |
||
136 | public function isLoaded() |
||
140 | |||
141 | /** |
||
142 | * Return the run status |
||
143 | * |
||
144 | * @return boolean |
||
145 | */ |
||
146 | public function isRun() |
||
150 | |||
151 | /** |
||
152 | * Instantiate the Config object to obtains module's configuration |
||
153 | * |
||
154 | * @return void |
||
155 | */ |
||
156 | protected function loadConfig() |
||
165 | |||
166 | /** |
||
167 | * Save loaded informations from json file into the loadInfos property |
||
168 | * |
||
169 | * @return void |
||
170 | */ |
||
171 | protected function obtainLoadInfos() |
||
180 | |||
181 | /** |
||
182 | * Read and parse a json file |
||
183 | * |
||
184 | * @param string $jsonFilePath : The path to the file to read |
||
185 | * |
||
186 | * @return mixed Json parsed datas |
||
187 | * |
||
188 | * @throws Exception If the file is not found or for a json parser error |
||
189 | */ |
||
190 | protected static function readJsonFile($jsonFilePath) |
||
209 | |||
210 | /** |
||
211 | * Add a dependency to the module |
||
212 | * Used for needMe property in module infos |
||
213 | * |
||
214 | * @param string $dependencyName The dependency name to add |
||
215 | * |
||
216 | * @return $this |
||
217 | */ |
||
218 | public function addDependency($dependencyName) |
||
232 | |||
233 | /** |
||
234 | * Get path to the runner file |
||
235 | * |
||
236 | * @return string |
||
237 | * |
||
238 | * @throws Exception If the file not exists |
||
239 | */ |
||
240 | protected function obtainRunnerFile() |
||
263 | |||
264 | /** |
||
265 | * Run the module in a closure |
||
266 | * |
||
267 | * @return void |
||
268 | */ |
||
269 | public function runModule() |
||
287 | } |
||
288 |