1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the O2System PHP Framework package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @author Steeve Andrian Salim |
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
// ------------------------------------------------------------------------ |
13
|
|
|
|
14
|
|
|
namespace O2System\Reactor\Cli\Commanders; |
15
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------ |
17
|
|
|
|
18
|
|
|
use O2System\Kernel\Cli\Writers\Format; |
19
|
|
|
use O2System\Reactor\Cli\Commander; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class Build |
23
|
|
|
* @package O2System\Reactor\Cli\Commanders |
24
|
|
|
*/ |
25
|
|
|
class Build extends Commander |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Build::$commandVersion |
29
|
|
|
* |
30
|
|
|
* Command version. |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $commandVersion = '1.0.0'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Build::$commandDescription |
38
|
|
|
* |
39
|
|
|
* Command description. |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $commandDescription = 'CLI_BUILD_DESC'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Build::$commandOptions |
47
|
|
|
* |
48
|
|
|
* Command options. |
49
|
|
|
* |
50
|
|
|
* @var array |
51
|
|
|
*/ |
52
|
|
|
protected $commandOptions = [ |
53
|
|
|
'filename' => [ |
54
|
|
|
'description' => 'CLI_BUILD_FILENAME_HELP', |
55
|
|
|
'required' => false, |
56
|
|
|
], |
57
|
|
|
'main' => [ |
58
|
|
|
'description' => 'CLI_BUILD_MAIN_HELP', |
59
|
|
|
'required' => false, |
60
|
|
|
], |
61
|
|
|
'force' => [ |
62
|
|
|
'description' => 'CLI_BUILD_FORCE_HELP', |
63
|
|
|
'required' => false, |
64
|
|
|
], |
65
|
|
|
]; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Build::$optionFilename |
69
|
|
|
* |
70
|
|
|
* Build filename. |
71
|
|
|
* |
72
|
|
|
* @var string |
73
|
|
|
*/ |
74
|
|
|
protected $optionFilename; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Build::$optionMain |
78
|
|
|
* |
79
|
|
|
* Build main script. |
80
|
|
|
* |
81
|
|
|
* @var string |
82
|
|
|
*/ |
83
|
|
|
protected $optionMain; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Build::optionFilename |
87
|
|
|
* |
88
|
|
|
* @param string $name |
89
|
|
|
*/ |
90
|
|
|
public function optionFilename($filename) |
91
|
|
|
{ |
92
|
|
|
$this->optionFilename = str_replace('.phar', '', $filename) . '.phar'; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
// ------------------------------------------------------------------------ |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Build::optionMain |
99
|
|
|
* |
100
|
|
|
* @param string $name |
101
|
|
|
*/ |
102
|
|
|
public function optionMain($main) |
103
|
|
|
{ |
104
|
|
|
$this->optionMain = $main; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
// ------------------------------------------------------------------------ |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Build::execute |
111
|
|
|
* |
112
|
|
|
* @throws \ReflectionException |
113
|
|
|
*/ |
114
|
|
|
public function execute() |
115
|
|
|
{ |
116
|
|
|
$this->__callOptions(); |
|
|
|
|
117
|
|
|
|
118
|
|
|
$filename = empty($this->optionFilename) ? 'app.phar' : $this->optionFilename; |
119
|
|
|
$filename = str_replace('.phar', '', $filename); |
120
|
|
|
$filePath = PATH_ROOT . 'build' . DIRECTORY_SEPARATOR . $filename; |
|
|
|
|
121
|
|
|
|
122
|
|
|
if (ini_get('phar.readonly') == 1 and $this->optionForce === false) { |
|
|
|
|
123
|
|
|
output()->write( |
|
|
|
|
124
|
|
|
(new Format()) |
125
|
|
|
->setContextualClass(Format::DANGER) |
126
|
|
|
->setString(language()->getLine('CLI_BUILD_PHAR_READONLY')) |
127
|
|
|
->setNewLinesAfter(1) |
128
|
|
|
); |
129
|
|
|
exit(EXIT_ERROR); |
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
output()->verbose( |
|
|
|
|
133
|
|
|
(new Format()) |
134
|
|
|
->setContextualClass(Format::INFO) |
135
|
|
|
->setString(language()->getLine('CLI_BUILD_START')) |
136
|
|
|
->setNewLinesAfter(1) |
137
|
|
|
); |
138
|
|
|
|
139
|
|
|
// Remove build directory |
140
|
|
|
$fileDirectory = dirname($filePath) . DIRECTORY_SEPARATOR; |
141
|
|
|
if (is_dir($fileDirectory)) { |
142
|
|
|
$directoryHandle = opendir($fileDirectory); |
143
|
|
|
if ( ! $directoryHandle) { |
|
|
|
|
144
|
|
|
return false; |
145
|
|
|
} |
146
|
|
|
while ($file = readdir($directoryHandle)) { |
147
|
|
|
if ($file != '.' && $file != '..') { |
148
|
|
|
if (is_file($fileDirectory . $file)) { |
149
|
|
|
unlink($fileDirectory . $file); |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
closedir($directoryHandle); |
154
|
|
|
rmdir($fileDirectory); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
if ( ! is_writable(dirname($filePath))) { |
158
|
|
|
@mkdir(dirname($filePath), 0777, true); |
|
|
|
|
159
|
|
|
|
160
|
|
|
output()->verbose( |
161
|
|
|
(new Format()) |
162
|
|
|
->setContextualClass(Format::INFO) |
163
|
|
|
->setString(language()->getLine('CLI_BUILD_MAKE_DIRECTORY')) |
164
|
|
|
->setNewLinesAfter(1) |
165
|
|
|
); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
try { |
169
|
|
|
$pharData = new \PharData($filePath . '.tar'); |
170
|
|
|
$phar = $pharData->convertToExecutable(\Phar::PHAR); |
171
|
|
|
|
172
|
|
|
// Build from PATH_ROOT using Recursive Directory Iterator |
173
|
|
|
$phar->buildFromIterator(new \RecursiveIteratorIterator(new \RecursiveCallbackFilterIterator( |
174
|
|
|
new \RecursiveDirectoryIterator(PATH_ROOT, |
175
|
|
|
\FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS), |
176
|
|
|
function ($current, $key, $iterator) { |
|
|
|
|
177
|
|
|
if ($current->isDir()) { |
178
|
|
|
// exclude build directory |
179
|
|
|
if ($current->getFilename() === 'build') { |
180
|
|
|
return false; |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
return true; |
185
|
|
|
})), PATH_ROOT); |
186
|
|
|
|
187
|
|
|
// Define main script |
188
|
|
|
$main = 'public/index.php'; |
189
|
|
|
if (empty($this->optionMain)) { |
190
|
|
|
// Default Carbon Boilerplate Detection |
191
|
|
|
if (is_file(PATH_APP . 'console')) { |
192
|
|
|
$main = 'app/console'; |
193
|
|
|
|
194
|
|
|
output()->verbose( |
195
|
|
|
(new Format()) |
196
|
|
|
->setContextualClass(Format::WARNING) |
197
|
|
|
->setString(language()->getLine('CLI_BUILD_USE_CARBON_DEFAULT')) |
198
|
|
|
->setNewLinesAfter(1) |
199
|
|
|
); |
200
|
|
|
} |
201
|
|
|
} else { |
202
|
|
|
$main = $this->optionMain; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
$phar->setStub($phar->createDefaultStub($main)); |
206
|
|
|
|
207
|
|
|
output()->verbose( |
208
|
|
|
(new Format()) |
209
|
|
|
->setContextualClass(Format::INFO) |
210
|
|
|
->setString(language()->getLine('CLI_BUILD_START_GZ_COMPRESSION')) |
211
|
|
|
->setNewLinesAfter(1) |
212
|
|
|
); |
213
|
|
|
|
214
|
|
|
$pharData->convertToExecutable(\Phar::TAR, \Phar::GZ, '.phar.tgz'); |
215
|
|
|
|
216
|
|
|
output()->write( |
217
|
|
|
(new Format()) |
218
|
|
|
->setContextualClass(Format::SUCCESS) |
219
|
|
|
->setString(language()->getLine('CLI_BUILD_SUCCESSFUL')) |
220
|
|
|
->setNewLinesAfter(1) |
221
|
|
|
); |
222
|
|
|
} catch (\Exception $exception) { |
223
|
|
|
output()->write( |
224
|
|
|
(new Format()) |
225
|
|
|
->setContextualClass(Format::DANGER) |
226
|
|
|
->setString($exception->getMessage()) |
227
|
|
|
->setNewLinesAfter(1) |
228
|
|
|
); |
229
|
|
|
} |
230
|
|
|
} |
231
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.