|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Gii\Command; |
|
6
|
|
|
|
|
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
9
|
|
|
use Yiisoft\Yii\Gii\Generator\Controller\Generator; |
|
10
|
|
|
use Yiisoft\Yii\Gii\GeneratorCommandInterface; |
|
11
|
|
|
use Yiisoft\Yii\Gii\GeneratorInterface; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* This is the command line version of Gii - a code generator. |
|
15
|
|
|
* |
|
16
|
|
|
* You can use this command to generate controllers, actions, etc. For example, |
|
17
|
|
|
* to generate a controller with some actions, you can run: |
|
18
|
|
|
* |
|
19
|
|
|
* ``` |
|
20
|
|
|
* $ ./yii gii/controller OrderController --actions=index,view,edit |
|
21
|
|
|
* ``` |
|
22
|
|
|
*/ |
|
23
|
|
|
final class ControllerCommand extends BaseGenerateCommand |
|
24
|
|
|
{ |
|
25
|
|
|
protected static $defaultName = 'gii/controller'; |
|
26
|
|
|
|
|
27
|
|
|
protected function configure(): void |
|
28
|
|
|
{ |
|
29
|
|
|
$this->setDescription('Gii controller generator') |
|
30
|
|
|
->addArgument('controllerClass', InputArgument::REQUIRED, 'Name of the generated controller') |
|
31
|
|
|
->addOption('viewsPath', 'vp', InputArgument::OPTIONAL, 'Controller views path') |
|
32
|
|
|
->addOption('baseClass', 'b', InputArgument::OPTIONAL, 'Controller base class') |
|
33
|
|
|
->addOption('actions', 'a', InputArgument::OPTIONAL, 'Name of the controller actions'); |
|
34
|
|
|
parent::configure(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getGenerator(): GeneratorInterface |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->gii->getGenerator(Generator::getId()); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function createGeneratorCommand(InputInterface $input): GeneratorCommandInterface |
|
43
|
|
|
{ |
|
44
|
|
|
$actions = $input->getOption('actions'); |
|
45
|
|
|
$actions = $actions !== null ? explode(',', $actions) : ['index']; |
|
46
|
|
|
|
|
47
|
|
|
$template = $input->getOption('template'); |
|
48
|
|
|
$template ??= 'default'; |
|
49
|
|
|
|
|
50
|
|
|
return new \Yiisoft\Yii\Gii\Generator\Controller\Command( |
|
51
|
|
|
controllerClass: $input->getArgument('controllerClass'), |
|
52
|
|
|
viewsPath: (string)$input->getOption('viewsPath'), |
|
53
|
|
|
baseClass: (string)$input->getOption('baseClass'), |
|
54
|
|
|
actions: $actions, |
|
55
|
|
|
template: $template, |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|