Ejemplo n.º 1
0
 public function run($argc, $argv)
 {
     switch ($argv[2]) {
         case 'scaffold':
             $generator = new generator\Scaffold($this);
             $generator->generate($argv[3], array_slice($argv, 4));
             break;
         case 'controller':
             $generator = new generator\Controller($this);
             $generator->generate($argv[3]);
             break;
         case 'model':
             $generator = new generator\Model($this);
             $generator->generate($argv[3]);
             break;
         case 'views':
             $generator = new generator\Views($this);
             $generator->generate($argv[3]);
             break;
         case 'migration':
             $generator = new generator\Migration($this);
             $generator->generate($argv[3], array_slice($argv, 4));
             break;
     }
 }
Ejemplo n.º 2
0
 public function generate($name, $colDefs = array())
 {
     if (empty($colDefs)) {
         throw new Exception('Scaffold generator requires a list of columns/attributes');
     }
     $name = Inflector::pluralize($name);
     $migrationGen = new Migration($this->command);
     $migrationGen->generate("create_{$name}", $colDefs);
     $modelGen = new Model($this->command);
     $modelGen->generate($name);
     $controllerGen = new Controller($this->command);
     $controllerGen->generate($name);
     $viewsGen = new Views($this->command);
     $viewsGen->generate($name, $colDefs);
 }
Ejemplo n.º 3
0
 public function testExtractIndexes()
 {
     $columns = array(array('name' => 'title', 'type' => 'string'), array('name' => 'slug', 'type' => 'string'), array('name' => 'site_id', 'type' => 'integer'), array('name' => 'user_id', 'type' => 'integer'));
     $expected = array('site_id', 'user_id');
     $result = Migration::extractIndexes($columns);
     $this->assertEquals($expected, $result);
 }
Ejemplo n.º 4
0
 public function generate($name, $colDefs = array())
 {
     if (empty($colDefs)) {
         $tableName = Inflector::tableize($name);
         $datasource = ConnectionManager::getDataSource();
         $attributes = $datasource->generateAttributeMapFromTable($tableName);
     } else {
         $columns = Migration::parseColumnDefinitions($colDefs);
         $names = array_map(function ($col) {
             return $col['name'];
         }, $columns);
         $types = array_map(function ($col) {
             return $col['type'];
         }, $columns);
         $attributes = array_combine($names, $types);
     }
     $templates = array('add', 'edit', 'index', 'view');
     $vars = array('attributes' => $attributes, 'friendlyModelName' => Inflector::humanize(Inflector::classify($name)), 'modelVarName' => Inflector::lowerCamelize(Inflector::classify(Inflector::singularize($name))), 'pluralModelVarName' => Inflector::lowerCamelize(Inflector::pluralize($name)), 'controller' => Inflector::tableize($name));
     foreach ($templates as $template) {
         $data = $this->_renderTemplate("views/{$template}", $vars, true);
         $folder = Inflector::tableize($name);
         $this->_writeFile("/views/{$folder}/{$template}.html.tpl", $data);
     }
 }