Ejemplo n.º 1
0
 private function generate()
 {
     $controller = $this->input->getArgument('controller');
     $action = $this->input->getArgument('action');
     $controllerGenerator = new ControllerGenerator($controller);
     $actionGenerator = null;
     if ($action) {
         $actionGenerator = new ActionGenerator($action);
     }
     $this->output->writeln('---------------------------------');
     $this->output->writeln('Class name: <info>' . $controllerGenerator->getClassName() . '</info>');
     $this->output->writeln('Class namespace: <info>' . $controllerGenerator->getClassNamespace() . '</info>');
     $this->output->writeln('---------------------------------');
     if (!$controllerGenerator->isControllerExists()) {
         $this->output->writeln('Create: <info>' . $controllerGenerator->getControllerPath() . '</info>');
         $controllerGenerator->saveController();
     }
     if ($controllerGenerator->appendAction($actionGenerator)) {
         $this->output->writeln('Appened action: <info>' . $controllerGenerator->getClassName() . '::' . $actionGenerator->getActionName() . '</info>');
     }
     $viewGenerator = new ViewGenerator($controller);
     if ($viewGenerator->createViewDirectoryIfNotExists()) {
         $this->output->writeln('Create: <info>' . $viewGenerator->getViewPath() . '</info>');
     }
     if ($viewGenerator->appendAction($actionGenerator)) {
         $this->output->writeln('Appened view file: <info>' . $actionGenerator->getActionViewFile() . '</info>');
     }
 }
Ejemplo n.º 2
0
 /**
  * @test
  */
 public function shouldNotAppendFileWhenExists()
 {
     //given
     $viewGenerator = new ViewGenerator('users', $this->path);
     $viewGenerator->createViewDirectoryIfNotExists();
     $actionGenerator = new ActionGenerator('save');
     $viewGenerator->appendAction($actionGenerator);
     //when
     $appendAction = $viewGenerator->appendAction($actionGenerator);
     //then
     $this->assertFalse($appendAction);
 }
Ejemplo n.º 3
0
 public function append()
 {
     if ($this->controllerGenerator) {
         $controllerPath = $this->controllerGenerator->getControllerPath();
         $controllerContents = $this->controllerGenerator->getControllerContents();
         $actionContents = $this->actionGenerator->templateContents();
         $controllerContents = preg_replace('/}\\s*$/', $actionContents . PHP_EOL . '}' . PHP_EOL, $controllerContents);
         file_put_contents($controllerPath, $controllerContents);
     }
     if ($this->viewGenerator) {
         file_put_contents(Path::join($this->viewGenerator->getViewPath(), $this->actionGenerator->getActionViewFile()), PHP_EOL);
     }
     return true;
 }