コード例 #1
0
 public function apiRestEntityAction()
 {
     $this->console = $this->getServiceLocator()->get('console');
     $tmpDir = sys_get_temp_dir();
     $request = $this->getRequest();
     $name = $request->getParam('name');
     $module = $request->getParam('module');
     $entity = $request->getParam('entity');
     $path = $request->getParam('path', '.');
     $doctrine = $this->getServiceLocator()->get("Doctrine\\ORM\\EntityManager");
     $modelController = new ModelController($name, $module, $path);
     $ucName = ucfirst($name);
     // criar o controller para apirest
     $modelController->setName("Api" . $name);
     $this->createApiRestController('API', $modelController);
     // create controller view
     $modelController->setName($name);
     $this->createApiRestController('VIEW', $modelController);
     // gerando o arquivo de configurações
     ModelConfig::generateConfig($module, $name, true, $path);
     $this->console->write("Configuration file regenerate!\n", Color::GREEN);
     // buscar a entidade e gerar o array para passar para os metodos que cuidam de gerar os inputs
     $arrayEntity = ModelDoctrine::readEntity($doctrine, $entity);
     $arrayInputs = ArrayForm::entityToForm($arrayEntity);
     // create class form
     $this->generateForm($name, $module, $arrayInputs, $path);
     die("okkk");
     // create class validate
     // criar o controller para view
     // add input form
     // add validation form
     // add methods index, list, edit, create
     return new ViewModel();
 }
コード例 #2
0
 public function apiRestAction()
 {
     $console = $this->getServiceLocator()->get('console');
     $tmpDir = sys_get_temp_dir();
     $request = $this->getRequest();
     $name = $request->getParam('name');
     $module = $request->getParam('modulo');
     $path = $request->getParam('path', '.');
     // generate controller
     $modelController = new ModelController($name, $module, $path);
     // add methods
     // method get
     $modelController->addMethod(new Generator\MethodGenerator('get', array(), Generator\MethodGenerator::FLAG_PUBLIC, 'return new JsonModel();'));
     // method getList
     $modelController->addMethod(new Generator\MethodGenerator('getList', array(), Generator\MethodGenerator::FLAG_PUBLIC, 'return new JsonModel();'));
     // method create
     $modelController->addMethod(new Generator\MethodGenerator('create', array(), Generator\MethodGenerator::FLAG_PUBLIC, 'return new JsonModel();'));
     // method update
     $modelController->addMethod(new Generator\MethodGenerator('update', array(), Generator\MethodGenerator::FLAG_PUBLIC, 'return new JsonModel();'));
     // method delete
     $modelController->addMethod(new Generator\MethodGenerator('delete', array(), Generator\MethodGenerator::FLAG_PUBLIC, 'return new JsonModel();'));
     // valida se o controller existe antes de criar
     if ($modelController->isControllerExist()) {
         // pergunta ao usuário
         $console->write("File exist, really want to delete?: ");
         $read = $console->readChar('yn');
         if ($read == "n") {
             $console->write("n\n", Color::RED);
             $console->write("Controller was not created.\n", Color::RED);
             return;
         }
         $console->write("y\n", Color::GREEN);
     }
     // generate class
     $modelController->generate();
     // echo text
     $console->write("Controller create success!\n", Color::GREEN);
     // gerando o arquivo de configurações
     ModelConfig::generateConfig($module, $name, false, $path);
     $console->write("Configuration file regenerate!\n", Color::GREEN);
 }