Example #1
0
 public function testParseColumnDefinitions()
 {
     $defs = array('title', 'slug', 'comments_count:integer', 'published:boolean');
     $expected = array(array('name' => 'title', 'type' => 'string'), array('name' => 'slug', 'type' => 'string'), array('name' => 'comments_count', 'type' => 'integer'), array('name' => 'published', 'type' => 'boolean'));
     $result = Migration::parseColumnDefinitions($defs);
     $this->assertEquals($expected, $result);
 }
Example #2
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);
     }
 }