示例#1
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', array($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;
 }
示例#2
0
 /**
  * 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', array($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;
 }
示例#3
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\\Crud\\' . 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', [], false);
     // 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
  *
  * @return bool
  */
 protected function generateClass($classDir, $className, $classText, ClassGeneratorInterface $generator)
 {
     // output message
     $this->console->writeTaskLine('task_generate_class_writing', array($classText));
     // set class file
     $classFile = $classDir . '/' . $className . '.php';
     // check if controller plugin file exists
     if (file_exists($classFile)) {
         $this->console->writeFailLine('task_generate_class_exists', array($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', array('repository'));
     // set factory file
     $factoryFile = $this->params->repositoryDir . '/' . $this->params->repositoryClassName . 'Factory.php';
     // check if factory file exists
     if (file_exists($factoryFile)) {
         $this->console->writeFailLine('task_generate_factory_exists', array('repository', $this->console->colorize($this->params->repositoryClassName, Color::GREEN), $this->console->colorize($this->params->paramModule, Color::GREEN)));
         return 1;
     }
     // create class
     $class = new RepositoryFactoryGenerator($this->params->repositoryClassName, $this->params->paramModule, $this->params->config['namespaceRepository'], $this->params->paramTableName, $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()
 {
     // 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', ['table gateway']);
         // set factory file
         $factoryFile = $this->params->tableGatewayDir . '/' . $tableConfig['tableGatewayClass'] . 'Factory.php';
         // check if factory file exists
         if (file_exists($factoryFile)) {
             $this->console->writeFailLine('task_generate_factory_exists', ['table gateway', $this->console->colorize($tableConfig['tableGatewayClass'], Color::GREEN), $this->console->colorize($this->params->paramModule, Color::GREEN)]);
             return 1;
         }
         // create class
         $class = new TableGatewayFactoryGenerator($tableConfig['tableGatewayClass'], $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;
 }
示例#10
0
 /**
  * Generate the factory
  *
  * @param string $factoryDir
  * @param string $factoryName
  * @param string $factoryText
  * @param string $namespaceName
  * @param string $managerName
  *
  * @return bool
  */
 protected function generateFactory($factoryDir, $factoryName, $factoryText, $namespaceName, $managerName)
 {
     if (!$this->params->paramFactory) {
         return true;
     }
     // output message
     $this->console->writeTaskLine('task_generate_factory_writing', array($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', array($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, $this->params->currentHydratorStrategies);
     // create file
     $file = new ClassFileGenerator($class->generate(), $this->params->config);
     // write file
     file_put_contents($factoryFile, $file->generate());
     return true;
 }