1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
tabletcommand.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\Cli\Command\Make;
4
5use Bitrix\Main\Cli\Command\Make\Service\Tablet\GenerateDto;
6use Bitrix\Main\Cli\Command\Make\Service\TabletService;
7use Symfony\Component\Console\Command\Command;
8use Symfony\Component\Console\Exception\InvalidArgumentException;
9use Symfony\Component\Console\Input\InputArgument;
10use Symfony\Component\Console\Input\InputInterface;
11use Symfony\Component\Console\Input\InputOption;
12use Symfony\Component\Console\Output\OutputInterface;
13
37final class TabletCommand extends Command
38{
39 private TabletService $service;
40
41 protected function configure(): void
42 {
43 $this->service = new TabletService();
44
45 $this
46 ->setName('make:tablet')
47 ->setDescription('Make ORM tablet for table')
48 ->addArgument('table_name', InputArgument::REQUIRED, 'table name')
49 ->addArgument('module', InputArgument::OPTIONAL, 'module id')
50 ->addOption('namespace', 'ns', InputOption::VALUE_REQUIRED, 'custom namespace')
51 ->addOption('root', null, InputOption::VALUE_REQUIRED, 'root folder for generate. Defaults server document root')
52 ->addOption('psr4', null, InputOption::VALUE_NEGATABLE, 'generate file path in PSR4 / camelCase style, ex: `module/lib/My/ClassName.php`', true)
53 ->addOption('show', null, InputOption::VALUE_NONE, 'outputs to console, without saving it. It can be used to save to an arbitrary location when using the `>` operator.')
54 ;
55 }
56
57 protected function execute(InputInterface $input, OutputInterface $output): int
58 {
59 $tableName = $input->getArgument('table_name');
60 if (!is_string($tableName))
61 {
62 throw new InvalidArgumentException('Table name must be string');
63 }
64
65 $dto = new GenerateDto(
66 tableName: $tableName,
67 namespace: $input->getOption('namespace'),
68 moduleId: $input->getArgument('module'),
69 rootFolder: $input->getOption('root'),
70 psr4: $input->getOption('psr4') === true,
71 );
72
73 if ($input->getOption('show') === true)
74 {
75 $output->write($this->service->generateContent($dto));
76 $output->writeln("\n");
77 }
78 else
79 {
80 $this->service->generateFile($dto);
81 }
82
83 return self::SUCCESS;
84 }
85}
execute(InputInterface $input, OutputInterface $output)
Определения tabletcommand.php:57
$output
Определения options.php:436