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