/** * Process the command * * @return integer */ public function processCommandTask() { // output message $this->console->writeTaskLine('task_delete_action_method_deleting'); // set controller file and action method $controllerFile = $this->params->controllerDir . '/' . $this->params->paramController . 'Controller.php'; // get file and class reflection $fileReflection = new FileReflection($controllerFile, true); $classReflection = $fileReflection->getClass($this->params->paramModule . '\\' . $this->params->config['namespaceController'] . '\\' . $this->params->paramController . 'Controller'); // setup class generator with reflected class $class = ClassGenerator::fromReflection($classReflection); // set method to check $actionMethod = strtolower($this->params->paramAction) . 'action'; // check for action method if (!$class->hasMethod($actionMethod)) { $this->console->writeFailLine('task_delete_action_method_not_exists', [$this->console->colorize($this->params->paramAction, Color::GREEN), $this->console->colorize($this->params->paramController, Color::GREEN), $this->console->colorize($this->params->paramModule, Color::GREEN)]); return 1; } // fix namespace usage $class->addUse('Zend\\Mvc\\Controller\\AbstractActionController'); $class->addUse('Zend\\View\\Model\\ViewModel'); $class->setExtendedClass('AbstractActionController'); $class->removeMethod($actionMethod); // create file $file = new ClassFileGenerator($class->generate(), $this->params->config); // write file file_put_contents($controllerFile, $file->generate()); return 0; }
/** * Process the command * * @return integer */ public function processCommandTask() { // output message $this->console->writeTaskLine('Writing action view script...'); // set action if ($this->params->paramAction) { $action = $this->filterCamelCaseToDash($this->params->paramAction); } else { $action = 'index'; } // set action file $actionFile = $this->params->controllerViewDir . DIRECTORY_SEPARATOR . $action . '.phtml'; // check if controller file exists if (file_exists($actionFile)) { $this->console->writeFailLine('task_generate_action_view_exists', [$this->console->colorize($actionFile, Color::GREEN), $this->console->colorize($this->params->paramController, Color::GREEN), $this->console->colorize($this->params->paramModule, Color::GREEN)]); return 1; } // create class $view = new ActionViewGenerator($this->filterDashToCamelCase($action), $this->params->paramController, $this->params->paramModule); // create file $file = new ClassFileGenerator($view->generate(), $this->params->config); // write file file_put_contents($actionFile, $file->generate()); return 0; }
/** * Process the command * * @return integer */ public function processCommandTask() { foreach (['index', 'show', 'create', 'update', 'delete'] as $viewName) { // output message $this->console->writeTaskLine('Writing ' . $viewName . ' action view script...'); // set action file $actionFile = $this->params->moduleViewDir . DIRECTORY_SEPARATOR . $viewName . DIRECTORY_SEPARATOR . 'index.phtml'; // check if controller file exists if (file_exists($actionFile)) { $this->console->writeFailLine('task_generate_action_view_exists', [$this->console->colorize($actionFile, Color::GREEN), $this->console->colorize($viewName, Color::GREEN), $this->console->colorize($this->params->paramEntityModule, Color::GREEN)]); return 1; } // set generator class $generatorClass = 'ZF2rapid\\Generator\\CrudGenerator\\' . ucfirst($viewName) . 'ActionViewGenerator'; // create class /** @var IndexActionViewGenerator $viewScript */ /** @var ShowActionViewGenerator $viewScript */ /** @var CreateActionViewGenerator $viewScript */ /** @var UpdateActionViewGenerator $viewScript */ /** @var DeleteActionViewGenerator $viewScript */ $viewScript = new $generatorClass($this->params->paramModule, $this->params->loadedEntity); // create file $file = new ClassFileGenerator($viewScript->generate(), $this->params->config); // write file file_put_contents($actionFile, '<?php' . "\n" . $file->generate()); } return 0; }
/** * Process the command * * @return integer */ public function processCommandTask() { // output message $this->console->writeTaskLine('task_module_generate_module_class_writing', []); // create class $class = new ModuleClassGenerator($this->params->paramModule, $this->params->moduleRootConstant, $this->params->config); // create file $file = new ClassFileGenerator($class->generate(), $this->params->config); // write file file_put_contents($this->params->moduleDir . '/Module.php', $file->generate()); return 0; }
/** * Generate the class * * @param string $classDir * @param string $className * @param string $classText * @param ClassGeneratorInterface $generator * @param bool $fileCheck * * @return bool */ protected function generateClass($classDir, $className, $classText, ClassGeneratorInterface $generator, $fileCheck = true) { // output message $this->console->writeTaskLine('task_generate_class_writing', [$classText]); // set class file $classFile = $classDir . '/' . $className . '.php'; // check if controller plugin file exists if ($fileCheck && file_exists($classFile)) { $this->console->writeFailLine('task_generate_class_exists', [$classText, $this->console->colorize($className, Color::GREEN), $this->console->colorize($this->params->paramModule, Color::GREEN)]); return false; } // create class $generator->build($className, $this->params->paramModule); // create file $file = new ClassFileGenerator($generator->generate(), $this->params->config); // write file file_put_contents($classFile, $file->generate()); return true; }
/** * Process the command * * @return integer */ public function processCommandTask() { // output message $this->console->writeTaskLine('task_generate_factory_writing', ['form']); // set factory file $factoryFile = $this->params->applicationFormDir . '/' . str_replace('Entity', '', $this->params->paramEntityClass) . 'DataFormFactory.php'; // check if factory file exists if (file_exists($factoryFile)) { $this->console->writeFailLine('task_generate_factory_exists', ['form', $this->console->colorize($this->params->paramModule . 'Form', Color::GREEN), $this->console->colorize($this->params->paramModule, Color::GREEN)]); return 1; } // create class $class = new DataFormFactoryGenerator(str_replace('Entity', '', $this->params->paramEntityClass) . 'DataForm', $this->params->paramModule, $this->params->paramEntityModule, $this->params->paramEntityClass, $this->params->loadedTables, $this->params->config); // create file $file = new ClassFileGenerator($class->generate(), $this->params->config); // write file file_put_contents($factoryFile, $file->generate()); return 0; }
/** * Process the command * * @return integer */ public function processCommandTask() { foreach ($this->params->tableConfig as $tableKey => $tableConfig) { // output message $this->console->writeTaskLine('task_generate_factory_writing', ['storage']); // set factory file $factoryFile = $this->params->storageDir . '/' . $tableConfig['storageClass'] . 'Factory.php'; // check if factory file exists if (file_exists($factoryFile)) { $this->console->writeFailLine('task_generate_factory_exists', ['storage', $this->console->colorize($tableConfig['storageClass'], Color::GREEN), $this->console->colorize($this->params->paramModule, Color::GREEN)]); return 1; } // create class $class = new StorageFactoryGenerator($tableConfig['storageClass'], $this->params->paramModule, $tableKey, $this->params->config, $this->params->loadedTables); // create file $file = new ClassFileGenerator($class->generate(), $this->params->config); // write file file_put_contents($factoryFile, $file->generate()); } return 0; }
/** * Process the command * * @return integer */ public function processCommandTask() { foreach (['Index', 'Show', 'Create', 'Update', 'Delete'] as $controllerName) { // output message $this->console->writeTaskLine('task_generate_factory_writing', [$controllerName . ' controller']); // set factory file $factoryFile = $this->params->applicationControllerDir . '/' . $controllerName . 'ControllerFactory.php'; // check if factory file exists if (file_exists($factoryFile)) { $this->console->writeFailLine('task_generate_factory_exists', ['index controller', $this->console->colorize($controllerName . 'ControllerFactory', Color::GREEN), $this->console->colorize($this->params->paramModule, Color::GREEN)]); return false; } // create class $class = new ControllerFactoryGenerator($controllerName . 'Controller', $this->params->paramModule, $this->params->paramEntityModule, $this->params->paramEntityClass, $this->params->config); // create file $file = new ClassFileGenerator($class->generate(), $this->params->config); // write file file_put_contents($factoryFile, $file->generate()); } return 0; }
/** * Generate the factory * * @param string $factoryDir * @param string $factoryName * @param string $factoryText * @param string $namespaceName * @param string $managerName * @param array $hydratorStrategies * * @return bool */ protected function generateFactory($factoryDir, $factoryName, $factoryText, $namespaceName, $managerName, array $hydratorStrategies = []) { if (!$this->params->paramFactory) { return true; } // output message $this->console->writeTaskLine('task_generate_factory_writing', [$factoryText]); // set factory file $factoryFile = $factoryDir . '/' . $factoryName . 'Factory.php'; // check if factory file exists if (file_exists($factoryFile)) { $this->console->writeFailLine('task_generate_factory_exists', [$factoryText, $this->console->colorize($factoryName, Color::GREEN), $this->console->colorize($this->params->paramModule, Color::GREEN)]); return false; } // create class $class = new FactoryGenerator($factoryName, $this->params->paramModule, $namespaceName, $managerName, $this->params->config, $hydratorStrategies); // create file $file = new ClassFileGenerator($class->generate(), $this->params->config); // write file file_put_contents($factoryFile, $file->generate()); return true; }