|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BFW\Install\Core\AppSystems; |
|
4
|
|
|
|
|
5
|
|
|
use \BFW\Core\AppSystems\AbstractSystem; |
|
6
|
|
|
use \BFW\Helpers\Cli; |
|
7
|
|
|
|
|
8
|
|
|
class ModuleInstall extends AbstractSystem |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var \BFW\Install\ModuleInstall[] $listToInstall |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $listToInstall = []; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* {@inheritdoc} |
|
17
|
|
|
* |
|
18
|
|
|
* @return $this |
|
19
|
|
|
*/ |
|
20
|
|
|
public function __invoke() |
|
21
|
|
|
{ |
|
22
|
|
|
return $this; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Getter accessor to property listToInstall |
|
27
|
|
|
* |
|
28
|
|
|
* @return type |
|
29
|
|
|
*/ |
|
30
|
|
|
public function getListToInstall() |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->listToInstall; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
|
|
public function init() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->initStatus = true; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* {@inheritdoc} |
|
45
|
|
|
*/ |
|
46
|
|
|
public function toRun() |
|
47
|
|
|
{ |
|
48
|
|
|
return true; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* {@inheritdoc} |
|
53
|
|
|
* Run install of all modules |
|
54
|
|
|
*/ |
|
55
|
|
|
public function run() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->installAllModules(); |
|
58
|
|
|
$this->runStatus = true; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Add a new module to the list to install |
|
63
|
|
|
* |
|
64
|
|
|
* @param \BFW\Install\ModuleInstall $module The new module |
|
65
|
|
|
* |
|
66
|
|
|
* @return $this |
|
67
|
|
|
*/ |
|
68
|
|
|
public function addToList(\BFW\Install\ModuleInstall $module) |
|
69
|
|
|
{ |
|
70
|
|
|
$moduleName = $module->getName(); |
|
71
|
|
|
|
|
72
|
|
|
$this->listToInstall[$moduleName] = $module; |
|
73
|
|
|
|
|
74
|
|
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Install all modules in the order of the dependency tree. |
|
79
|
|
|
* |
|
80
|
|
|
* @return void |
|
81
|
|
|
*/ |
|
82
|
|
|
protected function installAllModules() |
|
83
|
|
|
{ |
|
84
|
|
|
Cli::displayMsgNL('Read all modules to run install script...'); |
|
85
|
|
|
|
|
86
|
|
|
$tree = \BFW\Install\Application::getInstance() |
|
|
|
|
|
|
87
|
|
|
->getModuleList() |
|
88
|
|
|
->getLoadTree() |
|
89
|
|
|
; |
|
90
|
|
|
|
|
91
|
|
|
foreach ($tree as $firstLine) { |
|
92
|
|
|
foreach ($firstLine as $secondLine) { |
|
93
|
|
|
foreach ($secondLine as $moduleName) { |
|
94
|
|
|
if (!isset($this->listToInstall[$moduleName])) { |
|
95
|
|
|
continue; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
$this->installModule($moduleName); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
Cli::displayMsgNL('All modules have been read.'); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Install a module |
|
108
|
|
|
* |
|
109
|
|
|
* @param string $moduleName The module name |
|
110
|
|
|
* |
|
111
|
|
|
* @return void |
|
112
|
|
|
*/ |
|
113
|
|
|
protected function installModule($moduleName) |
|
114
|
|
|
{ |
|
115
|
|
|
if (!isset($this->listToInstall[$moduleName])) { |
|
116
|
|
|
return; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
Cli::displayMsgNL(' > Read for module '.$moduleName); |
|
120
|
|
|
|
|
121
|
|
|
$module = $this->listToInstall[$moduleName]; |
|
122
|
|
|
$installScripts = $module->getSourceInstallScript(); |
|
123
|
|
|
|
|
124
|
|
|
if ($installScripts === '') { |
|
125
|
|
|
Cli::displayMsgNL(' >> No script to run.'); |
|
126
|
|
|
return; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
if (is_string($installScripts)) { |
|
130
|
|
|
$installScripts = (array) $installScripts; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
foreach ($installScripts as $scriptPath) { |
|
|
|
|
|
|
134
|
|
|
$module->runInstallScript($scriptPath); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: