|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Bluz PHP Team |
|
4
|
|
|
* @link https://github.com/bluzphp/bluzman |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace Bluzman\Command\Generate; |
|
8
|
|
|
|
|
9
|
|
|
use Bluz\Validator\Validator as v; |
|
10
|
|
|
use Bluzman\Input\InputArgument; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* AbstractCommand |
|
16
|
|
|
* |
|
17
|
|
|
* @package Bluzman\Command |
|
18
|
|
|
*/ |
|
19
|
|
|
abstract class AbstractGenerateCommand extends \Bluzman\Command\AbstractCommand |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @param InputInterface $input |
|
23
|
|
|
* @param OutputInterface $output |
|
24
|
|
|
* @return mixed |
|
25
|
|
|
*/ |
|
26
|
|
|
abstract public function verify(InputInterface $input, OutputInterface $output); |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* addModuleArgument |
|
30
|
|
|
* |
|
31
|
|
|
* @return self |
|
32
|
|
|
*/ |
|
33
|
|
|
protected function addModuleArgument() |
|
34
|
|
|
{ |
|
35
|
|
|
$module = new InputArgument('module', InputArgument::REQUIRED, 'Module name is required'); |
|
36
|
|
|
$module->setValidator( |
|
37
|
|
|
v::string()->alphaNumeric('-_')->noWhitespace() |
|
38
|
|
|
); |
|
39
|
|
|
|
|
40
|
|
|
$this->getDefinition()->addArgument($module); |
|
41
|
|
|
|
|
42
|
|
|
return $this; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* addControllerArgument |
|
47
|
|
|
* |
|
48
|
|
|
* @return self |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function addControllerArgument() |
|
51
|
|
|
{ |
|
52
|
|
|
$controller = new InputArgument( |
|
53
|
|
|
'controller', |
|
54
|
|
|
InputArgument::REQUIRED, |
|
55
|
|
|
'Controller name is required' |
|
56
|
|
|
); |
|
57
|
|
|
$controller->setValidator( |
|
58
|
|
|
v::string()->alphaNumeric('-_')->noWhitespace() |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
$this->getDefinition()->addArgument($controller); |
|
62
|
|
|
|
|
63
|
|
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* addModelArguments |
|
68
|
|
|
* |
|
69
|
|
|
* @return self |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function addModelArgument() |
|
72
|
|
|
{ |
|
73
|
|
|
$model = new InputArgument('model', InputArgument::REQUIRED, 'Model name is required'); |
|
74
|
|
|
$model->setValidator( |
|
75
|
|
|
v::string()->alphaNumeric()->noWhitespace() |
|
76
|
|
|
); |
|
77
|
|
|
|
|
78
|
|
|
$this->getDefinition()->addArgument($model); |
|
79
|
|
|
|
|
80
|
|
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Required for correct mock it |
|
85
|
|
|
* |
|
86
|
|
|
* @param string $class |
|
87
|
|
|
* @return mixed |
|
88
|
|
|
*/ |
|
89
|
|
|
protected function getTemplate($class) |
|
90
|
|
|
{ |
|
91
|
|
|
$class = '\\Bluzman\\Generator\\Template\\' . $class ; |
|
92
|
|
|
return new $class; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
|
|
protected function getControllerPath($module, $controller) |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->getApplication()->getModulePath($module) |
|
101
|
|
|
. DS . 'controllers' |
|
102
|
|
|
. DS . $controller |
|
103
|
|
|
. '.php'; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @return string |
|
108
|
|
|
*/ |
|
109
|
|
|
protected function getViewPath($module, $controller) |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->getApplication()->getModulePath($module) |
|
112
|
|
|
. DS . 'views' |
|
113
|
|
|
. DS . $controller |
|
114
|
|
|
. '.phtml'; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|