|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the O2System Reactor 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\Make; |
|
15
|
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------ |
|
17
|
|
|
|
|
18
|
|
|
use O2System\Reactor\Cli\Commanders\Make; |
|
19
|
|
|
use O2System\Kernel\Cli\Writers\Format; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class Commander |
|
23
|
|
|
* |
|
24
|
|
|
* @package O2System\Reactor\Cli\Commanders\Make |
|
25
|
|
|
*/ |
|
26
|
|
|
class Commander extends Make |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* Commander::$commandDescription |
|
30
|
|
|
* |
|
31
|
|
|
* Command description. |
|
32
|
|
|
* |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $commandDescription = 'CLI_MAKE_COMMANDER_DESC'; |
|
36
|
|
|
|
|
37
|
|
|
// ------------------------------------------------------------------------ |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Commander::execute |
|
41
|
|
|
*/ |
|
42
|
|
|
public function execute() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->__callOptions(); |
|
45
|
|
|
|
|
46
|
|
|
if (empty($this->optionFilename)) { |
|
47
|
|
|
output()->write( |
|
|
|
|
|
|
48
|
|
|
(new Format()) |
|
49
|
|
|
->setContextualClass(Format::DANGER) |
|
50
|
|
|
->setString(language()->getLine('CLI_MAKE_COMMANDER_E_FILENAME')) |
|
51
|
|
|
->setNewLinesAfter(1) |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
exit(EXIT_ERROR); |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
if (strpos($this->optionPath, 'Commanders') === false) { |
|
58
|
|
|
$filePath = $this->optionPath . 'Commanders' . DIRECTORY_SEPARATOR . $this->optionFilename; |
|
59
|
|
|
} else { |
|
60
|
|
|
$filePath = $this->optionPath . $this->optionFilename; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$fileDirectory = dirname($filePath) . DIRECTORY_SEPARATOR; |
|
64
|
|
|
|
|
65
|
|
|
if ( ! is_dir($fileDirectory)) { |
|
66
|
|
|
mkdir($fileDirectory, 0777, true); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
if (is_file($filePath)) { |
|
70
|
|
|
output()->write( |
|
71
|
|
|
(new Format()) |
|
72
|
|
|
->setContextualClass(Format::DANGER) |
|
73
|
|
|
->setString(language()->getLine('CLI_MAKE_COMMANDER_E_EXISTS', [$filePath])) |
|
74
|
|
|
->setNewLinesAfter(1) |
|
75
|
|
|
); |
|
76
|
|
|
|
|
77
|
|
|
exit(EXIT_ERROR); |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
$className = prepare_class_name(pathinfo($filePath, PATHINFO_FILENAME)); |
|
81
|
|
|
@list($namespaceDirectory, $subNamespace) = explode('Commanders', dirname($filePath)); |
|
82
|
|
|
|
|
83
|
|
|
$classNamespace = loader()->getDirNamespace( |
|
84
|
|
|
$namespaceDirectory |
|
85
|
|
|
) . 'Commanders' . (empty($subNamespace) |
|
86
|
|
|
? null |
|
87
|
|
|
: str_replace( |
|
88
|
|
|
'/', |
|
89
|
|
|
'\\', |
|
90
|
|
|
$subNamespace |
|
91
|
|
|
)) . '\\'; |
|
92
|
|
|
|
|
93
|
|
|
$vars[ 'CREATE_DATETIME' ] = date('d/m/Y H:m'); |
|
|
|
|
|
|
94
|
|
|
$vars[ 'NAMESPACE' ] = trim($classNamespace, '\\'); |
|
95
|
|
|
$vars[ 'PACKAGE' ] = '\\' . trim($classNamespace, '\\'); |
|
96
|
|
|
$vars[ 'CLASS' ] = $className; |
|
97
|
|
|
$vars[ 'FILEPATH' ] = $filePath; |
|
98
|
|
|
|
|
99
|
|
|
$phpTemplate = <<<PHPTEMPLATE |
|
100
|
|
|
<?php |
|
101
|
|
|
/** |
|
102
|
|
|
* Created by O2System Reactor File Generator. |
|
103
|
|
|
* DateTime: CREATE_DATETIME |
|
104
|
|
|
*/ |
|
105
|
|
|
|
|
106
|
|
|
// ------------------------------------------------------------------------ |
|
107
|
|
|
|
|
108
|
|
|
namespace NAMESPACE; |
|
109
|
|
|
|
|
110
|
|
|
// ------------------------------------------------------------------------ |
|
111
|
|
|
|
|
112
|
|
|
use O2System\Reactor\Http\Commander; |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Class CLASS |
|
116
|
|
|
* |
|
117
|
|
|
* @package PACKAGE |
|
118
|
|
|
*/ |
|
119
|
|
|
class CLASS extends Commander |
|
120
|
|
|
{ |
|
121
|
|
|
/** |
|
122
|
|
|
* CLASS::index |
|
123
|
|
|
*/ |
|
124
|
|
|
public function index() |
|
125
|
|
|
{ |
|
126
|
|
|
// TODO: Change the autogenerated stub |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
PHPTEMPLATE; |
|
130
|
|
|
|
|
131
|
|
|
$fileContent = str_replace(array_keys($vars), array_values($vars), $phpTemplate); |
|
132
|
|
|
file_put_contents($filePath, $fileContent); |
|
133
|
|
|
|
|
134
|
|
|
if (is_file($filePath)) { |
|
135
|
|
|
output()->write( |
|
136
|
|
|
(new Format()) |
|
137
|
|
|
->setContextualClass(Format::SUCCESS) |
|
138
|
|
|
->setString(language()->getLine('CLI_MAKE_COMMANDER_S_MAKE', [$filePath])) |
|
139
|
|
|
->setNewLinesAfter(1) |
|
140
|
|
|
); |
|
141
|
|
|
|
|
142
|
|
|
exit(EXIT_SUCCESS); |
|
|
|
|
|
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
} |
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.