|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Rougin\Combustor\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
8
|
|
|
|
|
9
|
|
|
use Rougin\Combustor\Common\DataGenerator; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Make View Command |
|
13
|
|
|
* |
|
14
|
|
|
* @package Combustor |
|
15
|
|
|
* @author Rougin Royce Gutib <[email protected]> |
|
16
|
|
|
*/ |
|
17
|
|
|
class MakeViewCommand extends AbstractCommand |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Set the configurations of the specified command. |
|
21
|
|
|
* |
|
22
|
|
|
* @return void |
|
23
|
|
|
*/ |
|
24
|
9 |
|
protected function configure() |
|
25
|
|
|
{ |
|
26
|
9 |
|
$this->setName('make:view')->setDescription('Create a new view folder'); |
|
27
|
9 |
|
$this->addArgument('table', InputArgument::REQUIRED, 'Name of the table'); |
|
28
|
9 |
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Executes the current command. |
|
32
|
|
|
* |
|
33
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
|
34
|
|
|
* @param \Symfony\Component\Console\Input\OutputInterface $output |
|
35
|
|
|
* @return void |
|
36
|
|
|
*/ |
|
37
|
6 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
38
|
|
|
{ |
|
39
|
6 |
|
$contents = (new DataGenerator($this->describe, $input))->generate(); |
|
40
|
6 |
|
$filename = strtolower(plural(underscore($input->getArgument('table')))); |
|
41
|
|
|
|
|
42
|
6 |
|
$views = [ 'create', 'edit', 'index', 'show' ]; |
|
43
|
|
|
|
|
44
|
6 |
|
foreach ($views as $item) { |
|
45
|
6 |
|
$file = 'application/views/' . $filename . '/' . $item . '.php'; |
|
46
|
6 |
|
$view = $this->renderer->render('Views/' . ucfirst($item) . '.twig', $contents); |
|
47
|
|
|
|
|
48
|
6 |
|
$this->filesystem->write($file, $view); |
|
49
|
6 |
|
} |
|
50
|
|
|
|
|
51
|
6 |
|
$output->writeln('<info>Views created successfully!</info>'); |
|
52
|
6 |
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|