/** * Executa o comando. * * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $name = $input->getArgument('name'); $parts = explode('\\', $name); $class_name = end($parts); $folder_name = nameToFolderName($name, 'Models'); $root_ns = Config::getInstance()->get('root-namespace'); if ($input->getOption('tablename')) { $table_name = $input->getOption('tablename'); } else { $name = str_replace('\\', '', $name); preg_match_all('/([A-Z][a-z]+)/', $name, $teste); $table_name = implode('_', $teste[1]); $table_name = strtolower($table_name); } $tmp_name_folder = str_replace('/', '\\', $folder_name); $params = ['model_name' => $class_name, 'dev_name' => Config::getInstance()->get('app.developer'), 'data' => date('d/m/Y'), 'namespace' => $root_ns . '\\Models' . $tmp_name_folder, 'table_name' => $table_name]; $template = TemplateHelper::getInstance()->render('model_template', $params); $cmd_file_path = SYS_ROOT . 'App' . DS . 'Models' . $folder_name . DS . $class_name . 'Model.php'; if (is_file($cmd_file_path)) { $output->writeln('O model ' . $class_name . 'Model ja existe.'); return true; } $hand = fopen($cmd_file_path, 'w+'); fwrite($hand, $template); fclose($hand); $output->writeln('Model ' . $class_name . 'Model criado com sucesso.'); }
protected function execute(InputInterface $input, OutputInterface $output) { $name = trim($input->getArgument('name')); $parts = explode('\\', $name); $class_name = end($parts); $folder_name = nameToFolderName($name, 'Controllers'); $root_ns = Config::getInstance()->get('root-namespace'); $tmp_name_folder = str_replace('/', '\\', $folder_name); $params = ['controller_name' => nameToClassName($class_name), 'dev_name' => Config::getInstance()->get('app.developer'), 'data' => date('d/m/Y'), 'namespace' => $root_ns . '\\Controllers' . $tmp_name_folder]; $template = TemplateHelper::getInstance()->render('resource_template', $params); $cmd_file_path = SYS_ROOT . 'App' . DS . 'Controllers' . $folder_name . DS . $class_name . 'Controller.php'; if (is_file($cmd_file_path)) { $output->writeln('Anna: O Controlador ' . $class_name . 'Controller ja existe.'); return true; } $hand = fopen($cmd_file_path, 'a+'); if (!$hand) { $output->writeln('Anna: Não foi possível criar o arquivo do controlador.'); } fwrite($hand, $template); fclose($hand); //add controlador na router if (!$this->addResourceToRoute($class_name)) { $output->writeln('Anna: Nao foi possivel criar uma nova rota.'); } $output->writeln('Anna: Controlador ' . $class_name . 'Controller criado com sucesso.'); }
protected function execute(InputInterface $input, OutputInterface $output) { $cmd_name = $input->getArgument('name'); $cmd_description = $input->hasArgument('description') ? $input->getArgument('description') : ''; $class_name = nameToClassName($cmd_name); $dev_name = Config::getInstance()->get('app.developer'); $data = date('d/m/Y'); $root_ns = Config::getInstance()->get('root-namespace'); $params = ['command_class_name' => $class_name, 'dev_name' => $dev_name, 'data_atual' => $data, 'command_name' => $cmd_name, 'command_description' => $cmd_description, 'root_ns' => $root_ns]; $template = TemplateHelper::getInstance()->render('command_template', $params); $cmd_file_path = SYS_ROOT . 'App' . DS . 'Console' . DS . $class_name . 'Command.php'; $hand = fopen($cmd_file_path, 'a+'); fwrite($hand, $template); fclose($hand); $output->writeln('Comando ' . $class_name . 'Command criado com sucesso.'); }
protected function execute(InputInterface $input, OutputInterface $output) { $name = $input->getArgument('name'); $parts = explode('\\', $name); $class_name = end($parts); $folder_name = nameToFolderName($name, 'Repositories'); $root_ns = Config::getInstance()->get('root-namespace'); $tmp_name_folder = str_replace('/', '\\', $folder_name); $params = ['repository_name' => nameToClassName($class_name), 'dev_name' => Config::getInstance()->get('app.developer'), 'data' => date('d/m/Y'), 'namespace' => $root_ns . '\\Repositories' . $tmp_name_folder]; if ($input->getOption('model')) { $model = nameToClassName($class_name); if (!$this->callMakeModel($model, $output)) { $output->writeln('Anna: Nao foi possivel criar o modelo ' . $model . 'Model'); $params['construct'] = ''; $params['use_model'] = ''; } else { $model .= 'Model'; $declaration = 'public function __construct()' . EOL; $declaration .= "\t{" . EOL; $declaration .= "\t\t" . '$this->model = new ' . $model . '();' . EOL; $declaration .= "\t\t" . 'parent::__construct();' . EOL; $declaration .= "\t}" . EOL; $params['construct'] = $declaration; $params['use_model'] = 'use ' . $root_ns . '\\Models\\' . $model . ';'; } } else { $params['construct'] = ''; $params['use_model'] = ''; } if ($input->getOption('abstract')) { $params['use_suberclass'] = 'use Anna\\Repositories\\Abstracts\\Repository;'; } else { $params['use_suberclass'] = 'use Anna\\Repositories\\Repository;'; } $template = TemplateHelper::getInstance()->render('repository_template', $params); $cmd_file_path = SYS_ROOT . 'App' . DS . 'Repositories' . $folder_name . DS . $class_name . 'Repository.php'; if (is_file($cmd_file_path)) { $output->writeln('O Repositorio ' . $class_name . 'Repository ja existe.'); return true; } $hand = fopen($cmd_file_path, 'a+'); fwrite($hand, $template); fclose($hand); $output->writeln('Anna: Repositorio ' . $class_name . 'Repository criado com sucesso.'); }
/** * Executa o comando. * * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $name = $input->getArgument('name'); $parts = explode('\\', $name); $class_name = end($parts); $folder_name = nameToFolderName($name, 'Watchers'); $root_ns = Config::getInstance()->get('root-namespace'); $tmp_name_folder = str_replace('/', '\\', $folder_name); $params = ['watcher_name' => $class_name, 'dev_name' => Config::getInstance()->get('app.developer'), 'data' => date('d/m/Y'), 'namespace' => $root_ns . '\\Watchers' . $tmp_name_folder]; $template = TemplateHelper::getInstance()->render('watcher_template', $params); $cmd_file_path = SYS_ROOT . 'App' . DS . 'Watchers' . $folder_name . DS . $class_name . 'Watcher.php'; if (is_file($cmd_file_path)) { $output->writeln('O watcher ' . $class_name . 'Watcher ja existe.'); return true; } $hand = fopen($cmd_file_path, 'w+'); fwrite($hand, $template); fclose($hand); $output->writeln('Watcher ' . $class_name . 'Watcher criado com sucesso.'); }
protected function execute(InputInterface $input, OutputInterface $output) { $name = trim($input->getArgument('name')); $parts = explode('\\', $name); $class_name = end($parts); $folder_name = nameToFolderName($name, 'Controllers'); $view_folder = strtolower(str_replace(DS, '', $folder_name)); $root_ns = Config::getInstance()->get('root-namespace'); $ns_foldername = str_replace('/', '\\', $folder_name); $params = ['controller_name' => nameToClassName($class_name), 'dev_name' => Config::getInstance()->get('app.developer'), 'data' => date('d/m/Y'), 'namespace' => $root_ns . '\\Controllers' . $ns_foldername, 'view_folder' => $view_folder ? $view_folder . '.' : '']; if ($input->getOption('view')) { if (!$this->generateView($class_name)) { $output->writeln('Anna: Não foi possível criar o arquivo de view.'); $params['show_view'] = ''; } else { $view_folder = strtolower($class_name); $params['show_view'] = 'return view("' . $view_folder . '.index");'; } } else { $params['show_view'] = '//do the thing'; } $template = TemplateHelper::getInstance()->render('controller_template', $params); $cmd_file_path = SYS_ROOT . 'App' . DS . 'Controllers' . $folder_name . DS . $class_name . 'Controller.php'; if (is_file($cmd_file_path)) { $output->writeln('Anna: O Controlador ' . $class_name . 'Controller ja existe.'); return true; } $hand = fopen($cmd_file_path, 'a+'); if (!$hand) { $output->writeln('Anna: Não foi possível criar o arquivo do controlador.'); } fwrite($hand, $template); fclose($hand); //add controlador na router if (!$this->addControllerToRoute($class_name)) { $output->writeln('Anna: Nao foi possivel criar uma nova rota.'); } $output->writeln('Anna: Controlador ' . $class_name . 'Controller criado com sucesso.'); }