|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the O2System 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\Framework\Cli\Commanders\Make; |
|
15
|
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------ |
|
17
|
|
|
|
|
18
|
|
|
use O2System\Framework\Cli\Commanders\Make; |
|
19
|
|
|
use O2System\Kernel\Cli\Writers\Format; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class Plugin |
|
23
|
|
|
* |
|
24
|
|
|
* @package O2System\Framework\Cli\Commanders\Make |
|
25
|
|
|
*/ |
|
26
|
|
|
class Plugin extends Make |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* Plugin::$optionName |
|
30
|
|
|
* |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
public $optionName; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Plugin::$commandDescription |
|
37
|
|
|
* |
|
38
|
|
|
* Command description. |
|
39
|
|
|
* |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $commandDescription = 'CLI_MAKE_MODULE_DESC'; |
|
43
|
|
|
|
|
44
|
|
|
// ------------------------------------------------------------------------ |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Plugin::optionName |
|
48
|
|
|
* |
|
49
|
|
|
* @param string $name |
|
50
|
|
|
*/ |
|
51
|
|
|
public function optionName($name) |
|
52
|
|
|
{ |
|
53
|
|
|
if (empty($this->optionPath)) { |
|
54
|
|
|
$this->optionPath = PATH_APP . 'Modules' . DIRECTORY_SEPARATOR; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$this->optionName = $name; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
// ------------------------------------------------------------------------ |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Plugin::execute |
|
64
|
|
|
*/ |
|
65
|
|
|
public function execute() |
|
66
|
|
|
{ |
|
67
|
|
|
parent::execute(); |
|
68
|
|
|
|
|
69
|
|
|
if (empty($this->optionName)) { |
|
70
|
|
|
output()->write( |
|
|
|
|
|
|
71
|
|
|
(new Format()) |
|
72
|
|
|
->setContextualClass(Format::DANGER) |
|
73
|
|
|
->setString(language()->getLine('CLI_MAKE_MODULE_E_NAME')) |
|
74
|
|
|
->setNewLinesAfter(1) |
|
75
|
|
|
); |
|
76
|
|
|
|
|
77
|
|
|
exit(EXIT_ERROR); |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
$moduleType = empty($this->moduleType) |
|
|
|
|
|
|
81
|
|
|
? 'Plugins' |
|
82
|
|
|
: ucfirst(plural($this->moduleType)); |
|
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
if (strpos($this->optionPath, $moduleType) === false) { |
|
85
|
|
|
$modulePath = $this->optionPath . $moduleType . DIRECTORY_SEPARATOR . $this->optionName . DIRECTORY_SEPARATOR; |
|
86
|
|
|
} else { |
|
87
|
|
|
$modulePath = $this->optionPath . $this->optionName . DIRECTORY_SEPARATOR; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
if ( ! is_dir($modulePath)) { |
|
91
|
|
|
mkdir($modulePath, 0777, true); |
|
92
|
|
|
} else { |
|
93
|
|
|
output()->write( |
|
94
|
|
|
(new Format()) |
|
95
|
|
|
->setContextualClass(Format::DANGER) |
|
96
|
|
|
->setString(language()->getLine('CLI_MAKE_PLUGIN_E_EXISTS', [$modulePath])) |
|
97
|
|
|
->setNewLinesAfter(1) |
|
98
|
|
|
); |
|
99
|
|
|
|
|
100
|
|
|
exit(EXIT_ERROR); |
|
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
$jsonProperties[ 'name' ] = readable( |
|
|
|
|
|
|
104
|
|
|
pathinfo($modulePath, PATHINFO_FILENAME), |
|
105
|
|
|
true |
|
106
|
|
|
); |
|
107
|
|
|
|
|
108
|
|
|
if (empty($this->namespace)) { |
|
109
|
|
|
@list($moduleDirectory, $moduleName) = explode($moduleType, dirname($modulePath)); |
|
110
|
|
|
$namespace = loader()->getDirNamespace($moduleDirectory) . |
|
111
|
|
|
$moduleType . '\\' . prepare_class_name( |
|
112
|
|
|
$this->optionName |
|
113
|
|
|
) . '\\'; |
|
114
|
|
|
} else { |
|
115
|
|
|
$namespace = $this->namespace; |
|
116
|
|
|
$jsonProperties[ 'namespace' ] = rtrim($namespace, '\\') . '\\'; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
$jsonProperties[ 'created' ] = date('d M Y'); |
|
120
|
|
|
|
|
121
|
|
|
loader()->addNamespace($namespace, $modulePath); |
|
122
|
|
|
|
|
123
|
|
|
$fileContent = json_encode($jsonProperties, JSON_PRETTY_PRINT); |
|
124
|
|
|
|
|
125
|
|
|
$filePath = $modulePath . strtolower(singular($moduleType)) . '.json'; |
|
126
|
|
|
|
|
127
|
|
|
file_put_contents($filePath, $fileContent); |
|
128
|
|
|
|
|
129
|
|
|
$this->optionPath = $modulePath; |
|
130
|
|
|
$this->optionFilename = prepare_filename($this->optionName) . '.php'; |
|
131
|
|
|
|
|
132
|
|
|
(new Controller()) |
|
133
|
|
|
->optionPath($this->optionPath) |
|
134
|
|
|
->optionFilename($this->optionFilename); |
|
135
|
|
|
|
|
136
|
|
|
if (is_dir($modulePath)) { |
|
137
|
|
|
output()->write( |
|
138
|
|
|
(new Format()) |
|
139
|
|
|
->setContextualClass(Format::SUCCESS) |
|
140
|
|
|
->setString(language()->getLine('CLI_MAKE_PLUGIN_S_MAKE', [$modulePath])) |
|
141
|
|
|
->setNewLinesAfter(1) |
|
142
|
|
|
); |
|
143
|
|
|
|
|
144
|
|
|
exit(EXIT_SUCCESS); |
|
|
|
|
|
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
} |
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.