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