setName('extensions/codingInit') ->setDescription('Extension coding init') ->addOption('--extension', '-x', InputOption::VALUE_REQUIRED, 'Extension name: "plugin/name", "theme/name"') ; } /** * @param InputInterface $input * @param OutputInterface $output * @return mixed */ protected function execute(InputInterface $input, OutputInterface $output) { $extension = $this->getExtensionByOption('extension', $input, $output); if ($extension === false) { return 1; } # create files & dirs $chmod = 0775; $dir = 'coding'; $list = [ $dir => false, $dir . '/index.php' => "codingTemplateAdd('Пример admin шаблона', 'example-admin-file.php');\n\$this->codingTemplateAdd('Пример frontend шаблона', 'example-frontend-file.php', ['admin'=>false]);", $dir . '/less' => false, $dir . '/scss' => false, $dir . '/tpl' => false, $dir . '/tpl/_admin.php' => "css('/css/admin.css');\n\n?>\n", $dir . '/tpl/example-admin-file.php' => "render('_admin');\n\n\$this->adminPageHeader('Список');\n?>\n", $dir . '/tpl/_frontend.php' => "css('/css/frontend.css');\n\n?>\n\n", $dir . '/tpl/example-frontend-file.php' => "render('_frontend');\n\n?>\n\n
Example frontend file
\n\n", ]; foreach ($list as $k => $v) { $path = $extension->path($k, ['mod' => false]); if ($v === false) { # dir if (! file_exists($path) && ! Files::makeDir($path, $chmod)) { Errors::set(_t('files', 'Unable to create directory "[dir]"', ['dir' => $path])); break; } } else { # file if (! file_exists($path) && ! Files::putFileContent($path, $v)) { Errors::set(_t('files', 'Unable to create file "[file]"', ['file' => $path])); break; } } } if (! Errors::no()) { foreach (Errors::get(true, false) as $error) { $output->writeln('' . $error . ''); } return 1; } } }