1 | <?php namespace Savannabits\JetstreamInertiaGenerator\Generators; |
||
14 | abstract class ViewGenerator extends Command { |
||
15 | |||
16 | use Helpers, Columns, Names; |
||
17 | |||
18 | /** |
||
19 | * @var Filesystem |
||
20 | */ |
||
21 | protected Filesystem $files; |
||
|
|||
22 | |||
23 | /** |
||
24 | * Relations |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $relations = []; |
||
29 | |||
30 | /** |
||
31 | * Create a new controller creator command instance. |
||
32 | * |
||
33 | * @param Filesystem $files |
||
34 | */ |
||
35 | public function __construct(Filesystem $files) |
||
36 | { |
||
37 | parent::__construct(); |
||
38 | |||
39 | $this->files = $files; |
||
40 | } |
||
41 | |||
42 | protected function getArguments() { |
||
43 | return [ |
||
44 | ['table_name', InputArgument::REQUIRED, 'Name of the existing table'], |
||
45 | // FIXME add OPTIONAL file_name argument |
||
46 | ]; |
||
47 | } |
||
48 | |||
49 | |||
50 | /** |
||
51 | * Append content to file only if if the content is not present in the file |
||
52 | * |
||
53 | * @param $path |
||
54 | * @param $content |
||
55 | * @return bool |
||
56 | */ |
||
57 | protected function appendIfNotAlreadyAppended($path, $content): bool |
||
58 | { |
||
59 | if (!$this->files->exists($path)) { |
||
60 | $this->makeDirectory($path); |
||
61 | $this->files->put($path, $content); |
||
62 | } else if (!$this->alreadyAppended($path, $content)) { |
||
63 | $this->files->append($path, $content); |
||
64 | } else { |
||
65 | return false; |
||
66 | } |
||
67 | |||
68 | return true; |
||
69 | |||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Execute the console command. |
||
74 | * |
||
75 | * @param InputInterface $input |
||
76 | * @param OutputInterface $output |
||
77 | * @return int |
||
78 | */ |
||
79 | protected function execute(InputInterface $input, OutputInterface $output) |
||
80 | { |
||
81 | $this->initCommonNames($this->argument('table_name'), $this->option('model-name')); |
||
82 | |||
83 | return parent::execute($input, $output); |
||
84 | } |
||
85 | |||
86 | } |
||
87 |