1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
componentcommand.php
См. документацию.
1<?php
2
4
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;
13use Symfony\Component\Console\Style\SymfonyStyle;
14
42final class ComponentCommand extends Command
43{
45
46 protected function configure(): void
47 {
48 $this->service = new ComponentService();
49
50 $this
51 ->setName('make:component')
52 ->setDescription('Create a simple component with a class and a template')
53 ->addArgument('name', InputArgument::REQUIRED, 'component name')
54 ->addOption('module', null, InputOption::VALUE_REQUIRED, 'module id')
55 ->addOption('no-module', null, InputOption::VALUE_NONE, 'component will be created in components folder, outside the module')
56 ->addOption('local', null, InputOption::VALUE_NONE, 'component will be created in DOCUMENT_ROOT/local folder')
57 ->addOption('root', null, InputOption::VALUE_REQUIRED, 'the root folder for generate. Defaults server document root')
58 ->addOption('show', null, InputOption::VALUE_NONE, 'outputs to console, without saving it')
59 ;
60 }
61
62 protected function execute(InputInterface $input, OutputInterface $output): int
63 {
64 [$namespace, $name] = $this->prepareComponentName($input);
65
66 $dto = new GenerateDto(
67 name: $name,
68 namespace: $namespace,
69 module: $input->getOption('module') ?? explode('.', $name)[0],
70 noModule: $input->getOption('no-module') === true,
71 local: $input->getOption('local') === true,
72 root: $input->getOption('root'),
73 );
74
75 $styledOutput = new SymfonyStyle($input, $output);
76
77 $pathToComponent = $this->service->getPathToComponent($dto);
78
79 if ($input->getOption('show') === true)
80 {
81 $styledOutput->title('===============CLASS===============');
82 $styledOutput->text($this->service->generateClassContent($dto));
83 $styledOutput->title('==============TEMPLATE=============');
84 $styledOutput->text($this->service->generateTemplateContent($dto));
85 $styledOutput->title('=============LANG FILE=============');
86 $styledOutput->text($this->service->generateLangContent($dto));
87 $styledOutput->title(' ');
88 $styledOutput->success("The component '$name' will be created using the path $pathToComponent\n");
89 }
90 else
91 {
92 $this->service->generateClassFile($dto);
93 $this->service->generateTemplateFile($dto);
94 $this->service->generateLangFile($dto);
95 $styledOutput->success("The component '$name' was created using the path $pathToComponent\n");
96 }
97
98 $styledOutput->title("===============USAGE===============");
99 $styledOutput->writeln(<<<PHP
100\$APPLICATION->IncludeComponent(
101 '{$namespace}:{$name}',
102 '',
103 [],
104);
105
106PHP);
107
108 return self::SUCCESS;
109 }
110
111 protected function prepareComponentName(InputInterface $input): array
112 {
113 $name = $input->getArgument('name');
114 if (!is_string($name))
115 {
116 throw new InvalidArgumentException('Component name must be a string');
117 }
118
120 {
121 throw new InvalidArgumentException('Invalid component name');
122 }
123
124 if (str_contains($name, ':'))
125 {
126 return explode(':', $name);
127 }
128
129 return ['bitrix', $name];
130 }
131}
global $APPLICATION
Определения include.php:80
prepareComponentName(InputInterface $input)
Определения componentcommand.php:111
execute(InputInterface $input, OutputInterface $output)
Определения componentcommand.php:62
static checkComponentName($componentName)
Определения component_engine.php:70
</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