protected function execute(InputInterface $input, OutputInterface $output) { $component = new BitrixComponent($input->getArgument('name')); if ($component->exists()) { $output->writeln("<error>Component {$componentName} already exists!</error>"); $output->writeln("<info>" . $component->getComponentDir() . "</info>"); return 1; } $namespace = $component->getNamespace(); $componentName = $component->getName(); $siteRoot = BitrixTool::getInstance()->getSiteRoot(); if (!$siteRoot) { $output->writeln("<error>Not in a Bitrix web root!</error>"); return 1; } $bitrixFolder = $input->getOption('bitrix') ? 'btrix' : 'local'; $componentFolder = "{$siteRoot}/{$bitrixFolder}/components/{$namespace}/{$componentName}"; $componentTemplateFolder = "{$componentFolder}/template/.default"; $componentFiles = array('description' => "{$componentFolder}/.description.php", 'parameters' => "{$componentFolder}/.parameters.php", 'component' => "{$componentFolder}/component.php", 'template' => "{$componentTemplateFolder}/template.php"); // Создаем структуру каталогов. if (!file_exists($componentTemplateFolder) && !$this->createFolder($componentTemplateFolder)) { return 1; } file_put_contents($componentFiles['component'], COMPONENT_TEMPLATE_COMPONENT); file_put_contents($componentFiles['parameters'], COMPONENT_TEMPLATE_PARAMETERS); file_put_contents($componentFiles['description'], COMPONENT_TEMPLATE_DESCRIPTION); file_put_contents($componentFiles['template'], COMPONENT_TEMPLATE_TEMPLATE); }
protected function execute(InputInterface $input, OutputInterface $output) { $bitrix = BitrixTool::getInstance(); $showCoreComponents = $input->getOption('bitrix'); $showLocalComponents = $input->getOption('local'); if (!$showCoreComponents && !$showLocalComponents) { $showCoreComponents = $showLocalComponents = true; } $components = array_merge($showCoreComponents ? $bitrix->getComponents('bitrix') : array(), $showLocalComponents ? $bitrix->getComponents('local') : array()); foreach ($components as $component) { $output->writeln("<info>{$component}</info>"); } }
protected function execute(InputInterface $input, OutputInterface $output) { $bitrix = BitrixTool::getInstance(); // Исходный компонент. $componentName = $input->getOption('component'); $component = new BitrixComponent($componentName); if (!$component->exists()) { $output->writeln("<error>Component {$componentName} not found </error>"); return 1; } // Копируемый шаблон. $srcTemplateName = $input->getArgument('source'); $srcTemplatePath = $component->getTemplatePath($srcTemplateName); if (!file_exists($srcTemplatePath)) { $output->writeln("<error>Template {$srcTemplatePath} not found for component {$componentName}</error>"); return 1; } // Шаблон сайта, в который будет скопирован шаблон. $siteTemplateName = $input->getOption('site-template'); if (!$siteTemplateName) { $output->writeln("<error>Site template name not specified!</error>"); $output->writeln("<comment>Use --site-template option to specify site template where " . "to place component template.</comment>"); return 1; } if (!$bitrix->siteTemplateExists($siteTemplateName)) { $output->writeln("<error>Site template {$siteTemplateName} does not exist</error>"); return 1; } // Название с которым будет скопирован шаблон. $dstTemplateName = $input->getArgument('destination'); if (!$dstTemplateName) { $dstTemplateName = $srcTemplateName; } // Путь к целевому шаблону. $dstTemplatePath = $component->getLocalTemplatePath($siteTemplateName, $dstTemplateName); if (file_exists($dstTemplatePath) && !$input->getOption('force')) { $output->writeln("<error>Template {$dstTemplateName} already exsist.</error>"); $output->writeln("<info>Use --force option to overwrite</info>"); return 1; } $output->writeln("<comment>Copying component template:</comment>"); $output->writeln("<comment>--> from:</comment> <info>{$srcTemplatePath}</info>"); $output->writeln("<comment>--> to:</comment> <info>{$dstTemplatePath}</info>"); FileSystemHelpers::CopyDir($srcTemplatePath, $dstTemplatePath); $output->writeln('<comment>Done!</comment>'); }
protected function execute(InputInterface $input, OutputInterface $output) { $siteRoot = BitrixTool::getInstance()->getSiteRoot(); $output->writeln("<info>{$siteRoot}</info>"); }