rougin /
combustor
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Rougin\Combustor\Commands; |
||||
| 4 | |||||
| 5 | use Symfony\Component\Console\Input\InputInterface; |
||||
| 6 | use Symfony\Component\Console\Output\OutputInterface; |
||||
| 7 | |||||
| 8 | use Rougin\Combustor\Common\File; |
||||
| 9 | use Rougin\Combustor\Common\Tools; |
||||
| 10 | use Rougin\Combustor\Generator\ViewGenerator; |
||||
| 11 | use Rougin\Combustor\Validator\ViewValidator; |
||||
| 12 | |||||
| 13 | /** |
||||
| 14 | * Create View Command |
||||
| 15 | * |
||||
| 16 | * Creates a list of views for CodeIgniter |
||||
| 17 | * |
||||
| 18 | * @package Combustor |
||||
| 19 | * @author Rougin Gutib <[email protected]> |
||||
| 20 | */ |
||||
| 21 | class CreateViewCommand extends AbstractCommand |
||||
| 22 | { |
||||
| 23 | /** |
||||
| 24 | * @var string |
||||
| 25 | */ |
||||
| 26 | protected $command = 'view'; |
||||
| 27 | |||||
| 28 | /** |
||||
| 29 | * Executes the command. |
||||
| 30 | * |
||||
| 31 | * @param \Symfony\Component\Console\Input\InputInterface $input |
||||
| 32 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||||
| 33 | * @return object|\Symfony\Component\Console\Output\OutputInterface |
||||
| 34 | */ |
||||
| 35 | 9 | protected function execute(InputInterface $input, OutputInterface $output) |
|||
| 36 | { |
||||
| 37 | 9 | $name = Tools::stripTableSchema(plural($input->getArgument('name'))); |
|||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 38 | |||||
| 39 | 9 | if ($input->getOption('keep')) { |
|||
| 40 | 3 | $name = Tools::stripTableSchema($input->getArgument('name')); |
|||
|
0 ignored issues
–
show
It seems like
$input->getArgument('name') can also be of type string[]; however, parameter $table of Rougin\Combustor\Common\Tools::stripTableSchema() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 41 | 2 | } |
|||
| 42 | |||||
| 43 | 9 | $validator = new ViewValidator($name); |
|||
| 44 | |||||
| 45 | 9 | if ($validator->fails()) { |
|||
| 46 | 3 | $message = $validator->getMessage(); |
|||
| 47 | |||||
| 48 | 3 | return $output->writeln('<error>' . $message . '</error>'); |
|||
| 49 | } |
||||
| 50 | |||||
| 51 | $data = [ |
||||
| 52 | 9 | 'isBootstrap' => $input->getOption('bootstrap'), |
|||
| 53 | 9 | 'isCamel' => $input->getOption('camel'), |
|||
| 54 | 9 | 'name' => $input->getArgument('name') |
|||
| 55 | 6 | ]; |
|||
| 56 | |||||
| 57 | 9 | $generator = new ViewGenerator($this->describe, $data); |
|||
| 58 | |||||
| 59 | 9 | $result = $generator->generate(); |
|||
| 60 | |||||
| 61 | $results = [ |
||||
| 62 | 9 | 'create' => $this->renderer->render('Views/create.tpl', $result), |
|||
| 63 | 9 | 'edit' => $this->renderer->render('Views/edit.tpl', $result), |
|||
| 64 | 9 | 'index' => $this->renderer->render('Views/index.tpl', $result), |
|||
| 65 | 9 | 'show' => $this->renderer->render('Views/show.tpl', $result) |
|||
| 66 | 6 | ]; |
|||
| 67 | |||||
| 68 | 9 | $filePath = APPPATH . 'views/' . $name; |
|||
|
0 ignored issues
–
show
|
|||||
| 69 | |||||
| 70 | 9 | $create = new File($filePath . '/create.php'); |
|||
| 71 | 9 | $edit = new File($filePath . '/edit.php'); |
|||
| 72 | 9 | $index = new File($filePath . '/index.php'); |
|||
| 73 | 9 | $show = new File($filePath . '/show.php'); |
|||
| 74 | |||||
| 75 | 9 | $create->putContents($results['create']); |
|||
| 76 | 9 | $edit->putContents($results['edit']); |
|||
| 77 | 9 | $index->putContents($results['index']); |
|||
| 78 | 9 | $show->putContents($results['show']); |
|||
| 79 | |||||
| 80 | 9 | $create->close(); |
|||
| 81 | 9 | $edit->close(); |
|||
| 82 | 9 | $index->close(); |
|||
| 83 | 9 | $show->close(); |
|||
| 84 | |||||
| 85 | 9 | $message = 'The views folder "' . $name . '" has been created successfully!'; |
|||
| 86 | |||||
| 87 | 9 | return $output->writeln('<info>' . $message . '</info>'); |
|||
| 88 | } |
||||
| 89 | } |
||||
| 90 |