public function finish() { $colsDef = array(); $colsDef[] = "`id` INTEGER(11) UNSIGNED NOT NULL AUTO_INCREMENT"; foreach ($this->_columns as $column) { $expanded = Connection::expandColumn($column['type'], $column['options']); $colsDef[] = sprintf("`%s` %s", $column['name'], $expanded); } $colsDef[] = "PRIMARY KEY (`id`)"; $sql = array(); $sql[] = sprintf("CREATE TABLE `%s` (", $this->_tableName); $sql[] = implode(",\n", $colsDef); $sql[] = sprintf(") ENGINE %s;", $this->_options['engine']); $sql = implode("\n", $sql); $datasource = ConnectionManager::getDataSource(); $datasource->execute($sql); }
protected function _generateViews($name) { $tableName = Inflector::tableize($name); $datasource = ConnectionManager::getDataSource(); $attributes = $datasource->generateAttributeMapFromTable($tableName); $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); } }
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); } }
/** * undocumented function * * @return \rox\DataSource */ public static function datasource() { return ConnectionManager::getDataSource(static::$_dataSourceName); }
protected static function _flagAsMigrated($version, $direction) { $datasource = ConnectionManager::getDataSource(); if ($direction == 'up') { $sql = "INSERT INTO `schema_migrations`(`version`) VALUES('{$version}')"; $datasource->execute($sql); } else { $sql = "DELETE FROM `schema_migrations` WHERE `version` = '{$version}'"; $datasource->execute($sql); } }
protected function _datasource() { return ConnectionManager::getDataSource(); }