示例#1
0
 /**
  * @inheritDoc
  */
 public function generate()
 {
     $files = array();
     $db = $this->getDbConnection();
     $modelClass = ModelHelper::generateClassName($db, $db->tablePrefix, $this->subject);
     $controllerUse = !empty($this->modelNamespace) ? array("{$this->context}\\{$this->modelNamespace}\\{$modelClass}") : array();
     $files = array_merge($files, Generator::run(Generator::MODEL, array('subject' => $this->subject, 'context' => $this->context, 'template' => $this->modelTemplate, 'templatePath' => $this->getTemplatePath(), 'baseClass' => $this->modelBaseClass, 'namespace' => $this->modelNamespace)), Generator::run(Generator::CONTROLLER, array('subject' => $this->subject, 'context' => $this->context, 'template' => $this->controllerTemplate, 'templatePath' => $this->getTemplatePath(), 'baseClass' => $this->controllerBaseClass, 'namespace' => $this->controllerNamespace, 'actions' => $this->actions, 'providers' => array(array(Provider::CRUD, 'modelClass' => $modelClass, 'use' => $controllerUse)))));
     return $files;
 }
示例#2
0
 /**
  * @inheritDoc
  */
 public function generate()
 {
     $files = array();
     foreach ($this->generators as $name => $items) {
         foreach ($items as $config) {
             $config['subject'] = array_shift($config);
             $config['context'] = $this->subject;
             $files = array_merge(Generator::run($name, $config), $files);
         }
     }
     foreach ($this->directories as $dir) {
         $files[] = $this->createGitKeepFile($dir);
     }
     return $files;
 }
示例#3
0
 /**
  * Runs a specific generator with the given configuration.
  *
  * @param string $name name of the generator.
  * @param array $config generator configuration.
  * @param array $args command line arguments.
  */
 protected function runGenerator($name, array $config, array $args)
 {
     echo $this->renderVersion();
     if (!isset($args[0])) {
         $this->usageError("You must specify a subject for what you are generating.");
     }
     list($config['context'], $config['subject']) = strpos($args[0], ':') !== false ? explode(':', $args[0]) : array('app', $args[0]);
     echo Line::begin('Running generator', Line::YELLOW)->nl();
     echo Line::begin()->indent(2)->text("Generating {$name} '{$args[0]}'.")->nl(2);
     $generator = Generator::create($name, $config);
     if (!$generator->validate()) {
         $generator->renderErrors();
     }
     $files = $generator->generate();
     $this->save($files);
 }
示例#4
0
 /**
  * @inheritDoc
  */
 public function attributeHelp()
 {
     return array_merge(parent::attributeHelp(), array('template' => "Name of the template to use (default to '{$this->template}')"));
 }
 /**
  * @inheritDoc
  */
 public function generate()
 {
     $files = array();
     $this->actions = $this->normalizeActions($this->actions);
     $files[] = new File($this->resolveFilePath(), $this->compile(array('className' => $this->className, 'baseClass' => $this->baseClass, 'namespace' => $this->namespace, 'actions' => $this->renderActions())));
     foreach ($this->actions as $actionId) {
         if ($this->resolveTemplateFile(array("views/{$actionId}.txt", "views/view.txt")) === null) {
             continue;
         }
         $files = array_merge($files, Generator::run(Generator::VIEW, array('subject' => $actionId, 'context' => $this->context, 'template' => $this->template, 'filePath' => "views/{$this->subject}", 'templatePath' => "{$this->getTemplatePath()}/views", 'providers' => array(array(Provider::VIEW, 'cssClass' => "{$this->subject}-controller {$actionId}-action", 'vars' => array('this' => $this->resolveControllerClass()))))));
     }
     return $files;
 }