1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
controllercommand.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\Cli\Command\Make;
4
5use Bitrix\Main\Cli\Command\Make\Service\Controller\GenerateDto;
6use Bitrix\Main\Cli\Command\Make\Service\ControllerService;
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
47final class ControllerCommand extends Command
48{
49 private ControllerService $service;
50
51 protected function configure(): void
52 {
53 $this->service = new ControllerService();
54
55 $this
56 ->setName('make:controller')
57 ->setDescription('Make empty controller file')
58 ->addArgument('name', InputArgument::REQUIRED, 'controller name')
59 ->addArgument('module', InputArgument::OPTIONAL, 'module id')
60 ->addOption('namespace', 'ns', InputOption::VALUE_REQUIRED, 'custom namespace')
61 ->addOption('psr4', null, InputOption::VALUE_NEGATABLE, 'generate file path in PSR4 / camelCase style, ex: `module/lib/My/ClassName.php`', true)
62 ->addOption('root', null, InputOption::VALUE_REQUIRED, 'root folder for generate. Defaults server document root')
63 ->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.')
64 ->addOption('actions', null, InputArgument::OPTIONAL, 'generate given actions in controller. Use alias "crud" for CRUD actions')
65 ->addOption('alias', null, InputArgument::OPTIONAL, 'controller\'s namespace alias from .settings.php')
66 ;
67 }
68
69 protected function execute(InputInterface $input, OutputInterface $output): int
70 {
71 $name = $input->getArgument('name');
72 if (!is_string($name))
73 {
74 throw new InvalidArgumentException('Controller name must be string');
75 }
76
77 $dto = new GenerateDto(
78 name: $name,
79 moduleId: $input->getArgument('module'),
80 namespace: $input->getOption('namespace'),
81 rootFolder: $input->getOption('root'),
82 psr4: $input->getOption('psr4') === true,
83 actions: $this->resolveActions($input),
84 alias: $input->getOption('alias'),
85 );
86
87 if ($input->getOption('show') === true)
88 {
89 $output->write($this->service->generateContent($dto));
90 $output->writeln("\n");
91 }
92 else
93 {
94 $this->service->generateFile($dto);
95 }
96
97 return self::SUCCESS;
98 }
99
100 private function resolveActions(InputInterface $input): array
101 {
102 $actions = $input->getOption('actions');
103
104 if (empty($actions))
105 {
106 return [];
107 }
108
109 $actions = explode(',', $actions);
110
111 if (in_array('crud', $actions, true))
112 {
113 $actions = array_filter($actions, static fn(string$action): bool => $action !== 'crud');
114
115 $actions = array_merge(
116 $actions,
117 ['list', 'get', 'add', 'update', 'delete']
118 );
119
120 return array_unique($actions);
121 }
122
123 return $actions;
124 }
125}
execute(InputInterface $input, OutputInterface $output)
Определения controllercommand.php:69
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$output
Определения options.php:436
$name
Определения menu_edit.php:35
$action
Определения file_dialog.php:21