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; |
15
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------ |
17
|
|
|
|
18
|
|
|
use O2System\Framework\Cli\Commander; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class Make |
22
|
|
|
* |
23
|
|
|
* @package O2System\Framework\Cli\Commanders |
24
|
|
|
*/ |
25
|
|
|
class Make extends Commander |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Make::$commandVersion |
29
|
|
|
* |
30
|
|
|
* Command version. |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $commandVersion = '1.0.0'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Make::$commandDescription |
38
|
|
|
* |
39
|
|
|
* Command description. |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $commandDescription = 'CLI_MAKE_DESC'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Make::$commandOptions |
47
|
|
|
* |
48
|
|
|
* Command options. |
49
|
|
|
* |
50
|
|
|
* @var array |
51
|
|
|
*/ |
52
|
|
|
protected $commandOptions = [ |
53
|
|
|
'name' => [ |
54
|
|
|
'description' => 'CLI_MAKE_NAME_DESC', |
55
|
|
|
'required' => true, |
56
|
|
|
], |
57
|
|
|
'path' => [ |
58
|
|
|
'description' => 'CLI_MAKE_PATH_DESC', |
59
|
|
|
'required' => false, |
60
|
|
|
], |
61
|
|
|
'filename' => [ |
62
|
|
|
'description' => 'CLI_MAKE_FILENAME_DESC', |
63
|
|
|
'required' => true, |
64
|
|
|
], |
65
|
|
|
'namespace' => [ |
66
|
|
|
'description' => 'CLI_MAKE_NAMESPACE_DESC', |
67
|
|
|
'shortcut' => 'ns', |
68
|
|
|
'required' => false, |
69
|
|
|
], |
70
|
|
|
]; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Make::$path |
74
|
|
|
* |
75
|
|
|
* Make path. |
76
|
|
|
* |
77
|
|
|
* @var string |
78
|
|
|
*/ |
79
|
|
|
protected $optionPath; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Make::$filename |
83
|
|
|
* |
84
|
|
|
* Make filename. |
85
|
|
|
* |
86
|
|
|
* @var string |
87
|
|
|
*/ |
88
|
|
|
protected $optionFilename; |
89
|
|
|
|
90
|
|
|
// ------------------------------------------------------------------------ |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Make::optionPath |
94
|
|
|
* |
95
|
|
|
* @param string $path |
96
|
|
|
*/ |
97
|
|
|
public function optionPath($path) |
98
|
|
|
{ |
99
|
|
|
$path = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $path); |
100
|
|
|
$path = PATH_ROOT . str_replace(PATH_ROOT, '', $path); |
|
|
|
|
101
|
|
|
|
102
|
|
|
if (pathinfo($path, PATHINFO_EXTENSION)) { |
103
|
|
|
$this->optionFilename(pathinfo($path, PATHINFO_FILENAME)); |
104
|
|
|
$path = dirname($path); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$this->optionPath = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
// ------------------------------------------------------------------------ |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Make::optionFilename |
114
|
|
|
* |
115
|
|
|
* @param string $name |
116
|
|
|
*/ |
117
|
|
|
public function optionFilename($name) |
118
|
|
|
{ |
119
|
|
|
$name = str_replace('.php', '', $name); |
120
|
|
|
$this->optionFilename = prepare_filename($name) . '.php'; |
121
|
|
|
|
122
|
|
|
$this->optionPath = empty($this->optionPath) ? modules()->top()->getRealPath() : $this->optionPath; |
|
|
|
|
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
// ------------------------------------------------------------------------ |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Make::optionName |
129
|
|
|
* |
130
|
|
|
* @param string $name |
131
|
|
|
*/ |
132
|
|
|
public function optionName($name) |
133
|
|
|
{ |
134
|
|
|
$this->optionFilename($name); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
// ------------------------------------------------------------------------ |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Make::optionNamespace |
141
|
|
|
* |
142
|
|
|
* @param string $namespace |
143
|
|
|
*/ |
144
|
|
|
public function optionNamespace($namespace) |
145
|
|
|
{ |
146
|
|
|
$this->namespace = $namespace; |
|
|
|
|
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
// ------------------------------------------------------------------------ |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Make::getPhpTemplateFile |
153
|
|
|
* |
154
|
|
|
* @param string $filename |
155
|
|
|
*/ |
156
|
|
|
public function getPhpTemplateFile($filename) |
|
|
|
|
157
|
|
|
{ |
158
|
|
|
$directories = [ |
|
|
|
|
159
|
|
|
PATH_FRAMEWORK . 'Config' . DIRECTORY_SEPARATOR . 'PhpTemplateFiles', |
160
|
|
|
]; |
161
|
|
|
|
162
|
|
|
} |
163
|
|
|
} |