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);
 }
Exemple #2
0
	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);
		}
	}
Exemple #3
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);
     }
 }
Exemple #4
0
	/**
	 * undocumented function
	 *
	 * @return \rox\DataSource
	 */
	public static function datasource() {
		return ConnectionManager::getDataSource(static::$_dataSourceName);
	}
Exemple #5
0
 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);
     }
 }
Exemple #6
0
 protected function _datasource()
 {
     return ConnectionManager::getDataSource();
 }
 public function setUp()
 {
     ConnectionManager::setConfig('rox-test', array('class' => '\\rox\\test\\mocks\\active_record\\DataSource'));
 }
Exemple #8
0
    		'username' => 'root',
    		'password' => '',
    		'database' => 'rox_app'
    	));
    	break;
    
    case 'staging':
    	// Development database configuration
    	ConnectionManager::setConfig('default', array(
    		'host'     => '127.0.0.1',
    		'username' => 'root',
    		'password' => '',
    		'database' => 'rox_app_stage'
    	));
    	break;
    
    case 'test':
    	// Testing database configuration
    	ConnectionManager::setConfig('default', array(
    		'host'     => '127.0.0.1',
    		'username' => 'root',
    		'password' => '',
    		'database' => 'rox_app_test'
    	));
    	break;
    */
    default:
        // Development database configuration
        ConnectionManager::setConfig('default', array('host' => '127.0.0.1', 'username' => 'root', 'password' => '', 'database' => 'rox_app_dev'));
        break;
}