1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Bluz PHP Team |
4
|
|
|
* @link https://github.com/bluzphp/bluzman |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Bluzman\Application; |
8
|
|
|
|
9
|
|
|
use Bluz\Config\Config; |
10
|
|
|
use Bluz\Proxy; |
11
|
|
|
use Bluzman\Command; |
12
|
|
|
use Symfony\Component\Console; |
13
|
|
|
use Symfony\Component\Console\Input\InputDefinition; |
14
|
|
|
use Symfony\Component\Console\Input\InputOption; |
15
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @package Bluzman\Application |
19
|
|
|
* |
20
|
|
|
* @author Pavel Machekhin |
21
|
|
|
* @created 2013-11-28 12:31 |
22
|
|
|
*/ |
23
|
|
|
class Application extends Console\Application |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @param string $name |
27
|
|
|
* @param string $version |
28
|
|
|
*/ |
29
|
14 |
|
public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') |
30
|
|
|
{ |
31
|
14 |
|
parent::__construct($name, $version); |
32
|
|
|
|
33
|
14 |
|
$this->registerCommands(); |
34
|
14 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* init |
38
|
|
|
* |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
|
|
public function init() |
42
|
|
|
{ |
43
|
|
|
// Init Bluz config |
44
|
|
|
$config = new Config(); |
45
|
|
|
$config->setPath(PATH_APPLICATION); |
46
|
|
|
$config->setEnvironment(BLUZ_ENV); |
47
|
|
|
$config->init(); |
48
|
|
|
|
49
|
|
|
Proxy\Config::setInstance($config); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Removed some commands from default input definition. |
54
|
|
|
* |
55
|
|
|
* @return InputDefinition An InputDefinition instance |
56
|
|
|
*/ |
57
|
14 |
|
protected function getDefaultInputDefinition() |
58
|
|
|
{ |
59
|
14 |
|
return new InputDefinition( |
60
|
|
|
[ |
61
|
14 |
|
new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'), |
62
|
14 |
|
new InputOption( |
63
|
14 |
|
'--env', |
64
|
14 |
|
'-e', |
65
|
14 |
|
InputOption::VALUE_REQUIRED, |
66
|
14 |
|
'The environment to be used', |
67
|
14 |
|
getenv('BLUZ_ENV') ?: 'dev' |
68
|
|
|
), |
69
|
14 |
|
new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message'), |
70
|
14 |
|
new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message'), |
71
|
14 |
|
new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages'), |
72
|
14 |
|
new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this application version') |
73
|
|
|
] |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Register Bluzman commands |
79
|
|
|
* |
80
|
|
|
* @todo Find a way to do this automatically or move it to /bin/bluzman |
81
|
|
|
*/ |
82
|
14 |
|
protected function registerCommands() |
83
|
|
|
{ |
84
|
14 |
|
$this->addCommands( |
85
|
|
|
[ |
86
|
14 |
|
new Command\MagicCommand, |
87
|
14 |
|
new Command\RunCommand, |
88
|
14 |
|
new Command\TestCommand, |
89
|
14 |
|
new Command\Db\CreateCommand, |
90
|
14 |
|
new Command\Db\MigrateCommand, |
91
|
14 |
|
new Command\Db\RollbackCommand, |
92
|
14 |
|
new Command\Db\StatusCommand, |
93
|
14 |
|
new Command\Db\SeedCreateCommand, |
94
|
14 |
|
new Command\Db\SeedRunCommand, |
95
|
14 |
|
new Command\Generate\ModuleCommand, |
96
|
14 |
|
new Command\Generate\ControllerCommand, |
97
|
14 |
|
new Command\Generate\ModelCommand, |
98
|
14 |
|
new Command\Generate\CrudCommand, |
99
|
14 |
|
new Command\Generate\GridCommand, |
100
|
14 |
|
new Command\Generate\RestCommand, |
101
|
14 |
|
new Command\Module\InstallCommand, |
102
|
14 |
|
new Command\Module\ListCommand, |
103
|
14 |
|
new Command\Module\RemoveCommand, |
104
|
14 |
|
new Command\Server\StartCommand, |
105
|
14 |
|
new Command\Server\StopCommand, |
106
|
14 |
|
new Command\Server\StatusCommand, |
107
|
|
|
] |
108
|
|
|
); |
109
|
14 |
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Returns the path to the directory with bluzman application |
113
|
|
|
* |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
|
|
public function getWorkingPath() |
117
|
|
|
{ |
118
|
|
|
return getcwd(); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Get Module path |
123
|
|
|
* |
124
|
|
|
* @param string $name |
125
|
|
|
* @return string |
126
|
|
|
*/ |
127
|
3 |
|
public function getModulePath($name) |
128
|
|
|
{ |
129
|
3 |
|
return $this->getWorkingPath() . DIRECTORY_SEPARATOR |
130
|
3 |
|
. 'application' . DIRECTORY_SEPARATOR |
131
|
3 |
|
. 'modules' . DIRECTORY_SEPARATOR |
132
|
3 |
|
. $name; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Get Model path |
137
|
|
|
* |
138
|
|
|
* @param string $name |
139
|
|
|
* @return string |
140
|
|
|
*/ |
141
|
4 |
|
public function getModelPath($name) |
142
|
|
|
{ |
143
|
4 |
|
return $this->getWorkingPath() . DIRECTORY_SEPARATOR |
144
|
4 |
|
. 'application' . DIRECTORY_SEPARATOR |
145
|
4 |
|
. 'models' . DIRECTORY_SEPARATOR |
146
|
4 |
|
. $name; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param string $name |
151
|
|
|
* @return bool |
152
|
|
|
*/ |
153
|
2 |
|
public function isModuleExists($name) |
154
|
|
|
{ |
155
|
2 |
|
return is_dir($this->getModulePath($name)); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param string $name |
160
|
|
|
* @return bool |
161
|
|
|
*/ |
162
|
3 |
|
public function isModelExists($name) |
163
|
|
|
{ |
164
|
3 |
|
return is_dir($this->getModelPath($name)); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|