|
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
|
|
|
parent::execute(); |
|
117
|
|
|
|
|
118
|
|
|
$filename = empty($this->optionFilename) ? 'app.phar' : $this->optionFilename; |
|
119
|
|
|
$filePath = PATH_ROOT . 'build' . DIRECTORY_SEPARATOR . $filename; |
|
|
|
|
|
|
120
|
|
|
|
|
121
|
|
|
if(ini_get('phar.readonly') == 1 and $this->optionForce === false) { |
|
|
|
|
|
|
122
|
|
|
output()->write( |
|
|
|
|
|
|
123
|
|
|
(new Format()) |
|
124
|
|
|
->setContextualClass(Format::DANGER) |
|
125
|
|
|
->setString(language()->getLine('CLI_BUILD_PHAR_READONLY')) |
|
126
|
|
|
->setNewLinesAfter(1) |
|
127
|
|
|
); |
|
128
|
|
|
exit(EXIT_ERROR); |
|
|
|
|
|
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
output()->verbose( |
|
|
|
|
|
|
132
|
|
|
(new Format()) |
|
133
|
|
|
->setContextualClass(Format::INFO) |
|
134
|
|
|
->setString(language()->getLine('CLI_BUILD_START')) |
|
135
|
|
|
->setNewLinesAfter(1) |
|
136
|
|
|
); |
|
137
|
|
|
|
|
138
|
|
|
if ( ! is_writable(dirname($filePath))) { |
|
139
|
|
|
@mkdir(dirname($filePath), 0777, true); |
|
|
|
|
|
|
140
|
|
|
|
|
141
|
|
|
output()->verbose( |
|
142
|
|
|
(new Format()) |
|
143
|
|
|
->setContextualClass(Format::INFO) |
|
144
|
|
|
->setString(language()->getLine('CLI_BUILD_MAKE_DIRECTORY')) |
|
145
|
|
|
->setNewLinesAfter(1) |
|
146
|
|
|
); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
// Build Clean Up |
|
150
|
|
|
if (file_exists($filePath)) { |
|
151
|
|
|
unlink($filePath); |
|
152
|
|
|
output()->verbose( |
|
153
|
|
|
(new Format()) |
|
154
|
|
|
->setContextualClass(Format::WARNING) |
|
155
|
|
|
->setString(language()->getLine('CLI_BUILD_DELETE_OLD_BUILD')) |
|
156
|
|
|
->setNewLinesAfter(1) |
|
157
|
|
|
); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
if (file_exists($filePath . '.gz')) { |
|
161
|
|
|
unlink($filePath . '.gz'); |
|
162
|
|
|
output()->verbose( |
|
163
|
|
|
(new Format()) |
|
164
|
|
|
->setContextualClass(Format::WARNING) |
|
165
|
|
|
->setString(language()->getLine('CLI_BUILD_DELETE_OLD_BUILD_COMPRESSION')) |
|
166
|
|
|
->setNewLinesAfter(1) |
|
167
|
|
|
); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
$phar = new \Phar($filePath, 0, $filename); |
|
171
|
|
|
|
|
172
|
|
|
// Build from PATH_ROOT using Recursive Directory Iterator |
|
173
|
|
|
$phar->buildFromIterator( |
|
174
|
|
|
new \RecursiveIteratorIterator( |
|
175
|
|
|
new \RecursiveDirectoryIterator(PATH_ROOT, \FilesystemIterator::SKIP_DOTS)), |
|
176
|
|
|
PATH_ROOT); |
|
177
|
|
|
|
|
178
|
|
|
// Define main script |
|
179
|
|
|
$main = 'public/index.php'; |
|
180
|
|
|
if (empty($this->optionMain)) { |
|
181
|
|
|
// Default Carbon Boilerplate Detection |
|
182
|
|
|
if (is_file(PATH_APP . 'console')) { |
|
183
|
|
|
$main = 'app/console'; |
|
184
|
|
|
|
|
185
|
|
|
output()->verbose( |
|
186
|
|
|
(new Format()) |
|
187
|
|
|
->setContextualClass(Format::WARNING) |
|
188
|
|
|
->setString(language()->getLine('CLI_BUILD_USE_CARBON_DEFAULT')) |
|
189
|
|
|
->setNewLinesAfter(1) |
|
190
|
|
|
); |
|
191
|
|
|
} |
|
192
|
|
|
} else { |
|
193
|
|
|
$main = $this->optionMain; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
$phar->setStub($phar->createDefaultStub($main)); |
|
197
|
|
|
|
|
198
|
|
|
output()->verbose( |
|
199
|
|
|
(new Format()) |
|
200
|
|
|
->setContextualClass(Format::INFO) |
|
201
|
|
|
->setString(language()->getLine('CLI_BUILD_START_GZ_COMPRESSION')) |
|
202
|
|
|
->setNewLinesAfter(1) |
|
203
|
|
|
); |
|
204
|
|
|
|
|
205
|
|
|
$phar->compress(\Phar::GZ); |
|
206
|
|
|
|
|
207
|
|
|
output()->write( |
|
208
|
|
|
(new Format()) |
|
209
|
|
|
->setContextualClass(Format::SUCCESS) |
|
210
|
|
|
->setString(language()->getLine('CLI_BUILD_SUCCESSFUL')) |
|
211
|
|
|
->setNewLinesAfter(1) |
|
212
|
|
|
); |
|
213
|
|
|
} |
|
214
|
|
|
} |