1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BFW\Install; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Application class for install module script |
7
|
|
|
*/ |
8
|
|
|
class Application extends \BFW\Application |
9
|
|
|
{ |
10
|
|
|
protected static $modulesInstances = []; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* {@inheritdoc} |
14
|
|
|
*/ |
15
|
|
|
protected function initRequest() |
16
|
|
|
{ |
17
|
|
|
return; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* {@inheritdoc} |
22
|
|
|
*/ |
23
|
|
|
protected function initSession() |
24
|
|
|
{ |
25
|
|
|
return; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
protected function initErrors() |
32
|
|
|
{ |
33
|
|
|
return; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public static function addModuleInstallInstance( |
37
|
|
|
\BFW\Install\ModuleInstall $module |
38
|
|
|
) { |
39
|
|
|
$moduleName = $module->getName(); |
40
|
|
|
|
41
|
|
|
self::$modulesInstances[$moduleName] = $module; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
|
|
protected function declareRunPhases() |
48
|
|
|
{ |
49
|
|
|
$this->runPhases = [ |
50
|
|
|
[$this, 'loadMemcached'], |
51
|
|
|
[$this, 'readAllModules'], |
52
|
|
|
[$this, 'installModules'] |
53
|
|
|
]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
|
View Code Duplication |
public function run() |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
foreach ($this->runPhases as $action) { |
62
|
|
|
$action(); |
63
|
|
|
|
64
|
|
|
$notifyAction = $action; |
65
|
|
|
if (is_array($action)) { |
66
|
|
|
$notifyAction = $action[1]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$this->notifyAction('bfw_modules_install_run_'.$notifyAction); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$this->notifyAction('bfw_modules_install_finish'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
protected function installModules() |
76
|
|
|
{ |
77
|
|
|
echo 'Read all modules to run install script :'."\n"; |
78
|
|
|
|
79
|
|
|
$tree = $this->modules->getLoadTree(); |
80
|
|
|
|
81
|
|
|
foreach ($tree as $firstLine) { |
82
|
|
|
foreach ($firstLine as $secondLine) { |
83
|
|
|
foreach ($secondLine as $moduleName) { |
84
|
|
|
if (!isset(self::$modulesInstances[$moduleName])) { |
85
|
|
|
continue; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$this->installModule($moduleName); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
protected function installModule($moduleName) |
95
|
|
|
{ |
96
|
|
|
if (!isset(self::$modulesInstances[$moduleName])) { |
97
|
|
|
return; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
echo ' > Read for module '.$moduleName."\n"; |
101
|
|
|
|
102
|
|
|
$module = self::$modulesInstances[$moduleName]; |
103
|
|
|
$installScripts = $module->getSourceInstallScript(); |
104
|
|
|
|
105
|
|
|
if ($installScripts === '') { |
106
|
|
|
echo ' >> No script to run.'."\n"; |
107
|
|
|
return; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
if (is_string($installScripts)) { |
111
|
|
|
$installScripts = (array) $installScripts; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
foreach ($installScripts as $scriptPath) { |
115
|
|
|
$module->runInstall($scriptPath); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.