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\Commander; |
19
|
|
|
use O2System\Kernel\Cli\Writers\Format; |
20
|
|
|
use O2System\Kernel\Cli\Writers\Table; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class Registry |
24
|
|
|
* |
25
|
|
|
* @package O2System\Reactor\Cli\Commanders |
26
|
|
|
*/ |
27
|
|
|
class Registry extends Commander |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Make::$commandVersion |
31
|
|
|
* |
32
|
|
|
* Command version. |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $commandVersion = '1.0.0'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Make::$commandDescription |
40
|
|
|
* |
41
|
|
|
* Command description. |
42
|
|
|
* |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $commandDescription = 'CLI_REGISTRY_DESC'; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Make::$commandOptions |
49
|
|
|
* |
50
|
|
|
* Command options. |
51
|
|
|
* |
52
|
|
|
* @var array |
53
|
|
|
*/ |
54
|
|
|
protected $commandOptions = [ |
55
|
|
|
'update' => [ |
56
|
|
|
'description' => 'CLI_REGISTRY_UPDATE_DESC', |
57
|
|
|
'help' => 'CLI_REGISTRY_UPDATE_HELP', |
58
|
|
|
], |
59
|
|
|
'flush' => [ |
60
|
|
|
'description' => 'CLI_REGISTRY_FLUSH_DESC', |
61
|
|
|
], |
62
|
|
|
'info' => [ |
63
|
|
|
'description' => 'CLI_REGISTRY_INFO_DESC', |
64
|
|
|
], |
65
|
|
|
'metadata' => [ |
66
|
|
|
'description' => 'CLI_REGISTRY_METADATA_DESC', |
67
|
|
|
'help' => 'CLI_REGISTRY_METADATA_HELP', |
68
|
|
|
], |
69
|
|
|
]; |
70
|
|
|
|
71
|
|
|
// ------------------------------------------------------------------------ |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Registry::optionUpdate |
75
|
|
|
* |
76
|
|
|
* @param string|null $type |
77
|
|
|
*/ |
78
|
|
|
public function optionUpdate($type = null) |
79
|
|
|
{ |
80
|
|
|
if (in_array($type, ['modules', 'languages'])) { |
81
|
|
|
switch ($type) { |
82
|
|
|
case 'modules': |
83
|
|
|
modules()->updateRegistry(); |
|
|
|
|
84
|
|
|
break; |
85
|
|
|
|
86
|
|
|
case 'languages': |
87
|
|
|
language()->updateRegistry(); |
|
|
|
|
88
|
|
|
break; |
89
|
|
|
} |
90
|
|
|
} else { |
91
|
|
|
modules()->updateRegistry(); |
92
|
|
|
language()->updateRegistry(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
exit(EXIT_SUCCESS); |
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
// ------------------------------------------------------------------------ |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Registry::optionFlush |
102
|
|
|
* |
103
|
|
|
* @param string|null $type |
104
|
|
|
*/ |
105
|
|
|
public function optionFlush($type = null) |
106
|
|
|
{ |
107
|
|
|
if (in_array($type, ['modules', 'languages'])) { |
108
|
|
|
switch ($type) { |
109
|
|
|
case 'modules': |
110
|
|
|
modules()->flushRegistry(); |
|
|
|
|
111
|
|
|
break; |
112
|
|
|
|
113
|
|
|
case 'languages': |
114
|
|
|
language()->flushRegistry(); |
|
|
|
|
115
|
|
|
break; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
} else { |
119
|
|
|
modules()->flushRegistry(); |
120
|
|
|
language()->flushRegistry(); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
exit(EXIT_SUCCESS); |
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
// ------------------------------------------------------------------------ |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Registry::optionInfo |
130
|
|
|
*/ |
131
|
|
|
public function optionInfo() |
132
|
|
|
{ |
133
|
|
|
$table = new Table(); |
134
|
|
|
|
135
|
|
|
$table |
136
|
|
|
->addHeader('Metadata') |
137
|
|
|
->addHeader('Total'); |
138
|
|
|
|
139
|
|
|
$table |
140
|
|
|
->addRow() |
141
|
|
|
->addColumn('Modules') |
142
|
|
|
->addColumn(modules()->getTotalRegistry()); |
|
|
|
|
143
|
|
|
|
144
|
|
|
$table |
145
|
|
|
->addRow() |
146
|
|
|
->addColumn('Language') |
147
|
|
|
->addColumn(language()->getTotalRegistry()); |
|
|
|
|
148
|
|
|
|
149
|
|
|
output()->write( |
|
|
|
|
150
|
|
|
(new Format()) |
151
|
|
|
->setString($table->render()) |
152
|
|
|
->setNewLinesBefore(1) |
153
|
|
|
->setNewLinesAfter(2) |
154
|
|
|
); |
155
|
|
|
|
156
|
|
|
exit(EXIT_SUCCESS); |
|
|
|
|
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
// ------------------------------------------------------------------------ |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Registry::optionMetadata |
163
|
|
|
* |
164
|
|
|
* @param string $type |
165
|
|
|
*/ |
166
|
|
|
public function optionMetadata($type) |
167
|
|
|
{ |
168
|
|
|
if (in_array($type, ['modules', 'languages'])) { |
169
|
|
|
switch ($type) { |
170
|
|
|
case 'modules': |
171
|
|
|
$line = PHP_EOL . print_r(modules()->getRegistry(), true); |
|
|
|
|
172
|
|
|
break; |
173
|
|
|
|
174
|
|
|
case 'languages': |
175
|
|
|
$line = PHP_EOL . print_r(language()->getRegistry(), true); |
|
|
|
|
176
|
|
|
break; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
if (isset($line)) { |
180
|
|
|
output()->write($line); |
181
|
|
|
|
182
|
|
|
exit(EXIT_SUCCESS); |
|
|
|
|
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
} |