1 | <?php |
||
2 | |||
3 | namespace Apps\Console; |
||
4 | |||
5 | |||
6 | use Ffcms\Console\Command; |
||
7 | use Ffcms\Core\Helper\FileSystem\File; |
||
8 | use Ffcms\Core\Helper\Type\Str; |
||
9 | use Symfony\Component\Console\Input\InputInterface; |
||
10 | use Symfony\Component\Console\Input\InputOption; |
||
11 | use Symfony\Component\Console\Output\OutputInterface; |
||
12 | |||
13 | /** |
||
14 | * Class GeneratorActiveRecordCommand. Generate new active record model based on default carcase |
||
15 | * @package Apps\Console |
||
16 | */ |
||
17 | class GeneratorActiveRecordCommand extends Command |
||
18 | { |
||
19 | /** |
||
20 | * Register command |
||
21 | */ |
||
22 | public function configure() |
||
23 | { |
||
24 | $this->setName('generator:activerecord') |
||
25 | ->setDescription('Generate ActiveRecord model template') |
||
26 | ->addOption('name', 'name', InputOption::VALUE_OPTIONAL, 'Set active record model name'); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * Execute active record create |
||
31 | * @param InputInterface $input |
||
32 | * @param OutputInterface $output |
||
33 | * @return void |
||
34 | */ |
||
35 | public function execute(InputInterface $input, OutputInterface $output) |
||
36 | { |
||
37 | // get ar name from input |
||
38 | $name = $this->optionOrAsk('name', 'ActiveRecord name'); |
||
39 | $name = ucfirst(Str::lowerCase($name)); |
||
40 | |||
41 | $tpl = File::read('/Private/Carcase/ActiveRecord.tphp'); |
||
42 | $code = Str::replace('%name%', $name, $tpl); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
43 | |||
44 | $path = '/Apps/ActiveRecord/' . $name . '.php'; |
||
45 | File::write($path, $code); |
||
46 | $output->writeln('ActiveRecord are successful created: ' . $path); |
||
47 | } |
||
48 | } |