Commit e2d8a916 authored by lsmith's avatar lsmith

- fixed class name in comments

parent ebbfcf4c
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
*/ */
/** /**
* Doctrine_Migration_Builder * Doctrine_Builder_Migration
* *
* @package Doctrine * @package Doctrine
* @subpackage Builder * @subpackage Builder
...@@ -35,7 +35,7 @@ class Doctrine_Builder_Migration extends Doctrine_Builder ...@@ -35,7 +35,7 @@ class Doctrine_Builder_Migration extends Doctrine_Builder
{ {
/** /**
* migrationsPath * migrationsPath
* *
* The path to your migration classes directory * The path to your migration classes directory
* *
* @var string * @var string
...@@ -44,7 +44,7 @@ class Doctrine_Builder_Migration extends Doctrine_Builder ...@@ -44,7 +44,7 @@ class Doctrine_Builder_Migration extends Doctrine_Builder
/** /**
* suffix * suffix
* *
* File suffix to use when writing class definitions * File suffix to use when writing class definitions
* *
* @var string $suffix * @var string $suffix
...@@ -70,7 +70,7 @@ class Doctrine_Builder_Migration extends Doctrine_Builder ...@@ -70,7 +70,7 @@ class Doctrine_Builder_Migration extends Doctrine_Builder
if ($migrationsPath) { if ($migrationsPath) {
$this->setMigrationsPath($migrationsPath); $this->setMigrationsPath($migrationsPath);
} }
$this->_loadTemplate(); $this->_loadTemplate();
} }
...@@ -99,12 +99,12 @@ class Doctrine_Builder_Migration extends Doctrine_Builder ...@@ -99,12 +99,12 @@ class Doctrine_Builder_Migration extends Doctrine_Builder
/** /**
* loadTemplate * loadTemplate
* *
* Loads the class template used for generating classes * Loads the class template used for generating classes
* *
* @return void * @return void
*/ */
protected function _loadTemplate() protected function _loadTemplate()
{ {
if (isset(self::$_tpl)) { if (isset(self::$_tpl)) {
return; return;
...@@ -139,18 +139,18 @@ END; ...@@ -139,18 +139,18 @@ END;
$directory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tmp_doctrine_models'; $directory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tmp_doctrine_models';
Doctrine::generateModelsFromDb($directory); Doctrine::generateModelsFromDb($directory);
$result = $this->generateMigrationsFromModels($directory); $result = $this->generateMigrationsFromModels($directory);
Doctrine_Lib::removeDirectories($directory); Doctrine_Lib::removeDirectories($directory);
return $result; return $result;
} }
/** /**
* generateMigrationsFromModels * generateMigrationsFromModels
* *
* @param string $modelsPath * @param string $modelsPath
* @return void * @return void
*/ */
public function generateMigrationsFromModels($modelsPath = null) public function generateMigrationsFromModels($modelsPath = null)
...@@ -160,47 +160,47 @@ END; ...@@ -160,47 +160,47 @@ END;
} else { } else {
$models = Doctrine::getLoadedModels(); $models = Doctrine::getLoadedModels();
} }
$foreignKeys = array(); $foreignKeys = array();
foreach ($models as $model) { foreach ($models as $model) {
$export = Doctrine::getTable($model)->getExportableFormat(); $export = Doctrine::getTable($model)->getExportableFormat();
$foreignKeys[$export['tableName']] = $export['options']['foreignKeys']; $foreignKeys[$export['tableName']] = $export['options']['foreignKeys'];
$up = $this->buildCreateTable($export); $up = $this->buildCreateTable($export);
$down = $this->buildDropTable($export); $down = $this->buildDropTable($export);
$className = 'Add' . Doctrine::classify($export['tableName']); $className = 'Add' . Doctrine::classify($export['tableName']);
$this->generateMigrationClass($className, array(), $up, $down); $this->generateMigrationClass($className, array(), $up, $down);
} }
$className = 'ApplyForeignKeyConstraints'; $className = 'ApplyForeignKeyConstraints';
$up = ''; $up = '';
$down = ''; $down = '';
foreach ($foreignKeys as $tableName => $definitions) { foreach ($foreignKeys as $tableName => $definitions) {
$tableForeignKeyNames[$tableName] = array(); $tableForeignKeyNames[$tableName] = array();
foreach ($definitions as $definition) { foreach ($definitions as $definition) {
$definition['name'] = $tableName . '_' . $definition['foreignTable'] . '_' . $definition['local'] . '_' . $definition['foreign']; $definition['name'] = $tableName . '_' . $definition['foreignTable'] . '_' . $definition['local'] . '_' . $definition['foreign'];
$up .= $this->buildCreateForeignKey($tableName, $definition); $up .= $this->buildCreateForeignKey($tableName, $definition);
$down .= $this->buildDropForeignKey($tableName, $definition); $down .= $this->buildDropForeignKey($tableName, $definition);
} }
} }
$this->generateMigrationClass($className, array(), $up, $down); $this->generateMigrationClass($className, array(), $up, $down);
return true; return true;
} }
/** /**
* buildCreateForeignKey * buildCreateForeignKey
* *
* @param string $tableName * @param string $tableName
* @param string $definition * @param string $definition
* @return void * @return void
*/ */
public function buildCreateForeignKey($tableName, $definition) public function buildCreateForeignKey($tableName, $definition)
...@@ -211,8 +211,8 @@ END; ...@@ -211,8 +211,8 @@ END;
/** /**
* buildDropForeignKey * buildDropForeignKey
* *
* @param string $tableName * @param string $tableName
* @param string $definition * @param string $definition
* @return void * @return void
*/ */
public function buildDropForeignKey($tableName, $definition) public function buildDropForeignKey($tableName, $definition)
...@@ -223,26 +223,26 @@ END; ...@@ -223,26 +223,26 @@ END;
/** /**
* buildCreateTable * buildCreateTable
* *
* @param string $tableData * @param string $tableData
* @return void * @return void
*/ */
public function buildCreateTable($tableData) public function buildCreateTable($tableData)
{ {
$code = "\t\t\$this->createTable('" . $tableData['tableName'] . "', "; $code = "\t\t\$this->createTable('" . $tableData['tableName'] . "', ";
$code .= var_export($tableData['columns'], true) . ", "; $code .= var_export($tableData['columns'], true) . ", ";
$code .= var_export(array('indexes' => $tableData['options']['indexes'], 'primary' => $tableData['options']['primary']), true); $code .= var_export(array('indexes' => $tableData['options']['indexes'], 'primary' => $tableData['options']['primary']), true);
$code .= ");"; $code .= ");";
return $code; return $code;
} }
/** /**
* buildDropTable * buildDropTable
* *
* @param string $tableData * @param string $tableData
* @return string * @return string
*/ */
public function buildDropTable($tableData) public function buildDropTable($tableData)
...@@ -263,16 +263,16 @@ END; ...@@ -263,16 +263,16 @@ END;
if ( ! $this->getMigrationsPath()) { if ( ! $this->getMigrationsPath()) {
throw new Doctrine_Migration_Exception('You must specify the path to your migrations.'); throw new Doctrine_Migration_Exception('You must specify the path to your migrations.');
} }
$migration = new Doctrine_Migration($this->getMigrationsPath()); $migration = new Doctrine_Migration($this->getMigrationsPath());
$next = (string) $migration->getNextVersion(); $next = (string) $migration->getNextVersion();
$fileName = str_repeat('0', (3 - strlen($next))) . $next . '_' . Doctrine::tableize($className) . $this->_suffix; $fileName = str_repeat('0', (3 - strlen($next))) . $next . '_' . Doctrine::tableize($className) . $this->_suffix;
$class = $this->buildMigrationClass($className, $fileName, $options, $up, $down); $class = $this->buildMigrationClass($className, $fileName, $options, $up, $down);
$path = $this->getMigrationsPath() . DIRECTORY_SEPARATOR . $fileName; $path = $this->getMigrationsPath() . DIRECTORY_SEPARATOR . $fileName;
file_put_contents($path, $class); file_put_contents($path, $class);
} }
} }
...@@ -285,15 +285,15 @@ END; ...@@ -285,15 +285,15 @@ END;
public function buildMigrationClass($className, $fileName = null, $options = array(), $up = null, $down = null) public function buildMigrationClass($className, $fileName = null, $options = array(), $up = null, $down = null)
{ {
$extends = isset($options['extends']) ? $options['extends']:'Doctrine_Migration'; $extends = isset($options['extends']) ? $options['extends']:'Doctrine_Migration';
$content = '<?php' . PHP_EOL; $content = '<?php' . PHP_EOL;
$content .= sprintf(self::$_tpl, $className, $content .= sprintf(self::$_tpl, $className,
$extends, $extends,
$up, $up,
$down); $down);
return $content; return $content;
} }
} }
\ No newline at end of file
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
*/ */
/** /**
* Doctrine_Import_Builder * Doctrine_Builder_Record
* *
* Import builder is responsible of building Doctrine_Record classes * Import builder is responsible of building Doctrine_Record classes
* based on a database schema. * based on a database schema.
...@@ -40,13 +40,13 @@ class Doctrine_Builder_Record ...@@ -40,13 +40,13 @@ class Doctrine_Builder_Record
{ {
/** /**
* Path * Path
* *
* the path where imported files are being generated * the path where imported files are being generated
* *
* @var string $_path * @var string $_path
*/ */
protected $_path = ''; protected $_path = '';
/** /**
* packagesPrefix * packagesPrefix
* *
...@@ -60,10 +60,10 @@ class Doctrine_Builder_Record ...@@ -60,10 +60,10 @@ class Doctrine_Builder_Record
* @var string * @var string
*/ */
protected $_packagesPath = ''; protected $_packagesPath = '';
/** /**
* suffix * suffix
* *
* File suffix to use when writing class definitions * File suffix to use when writing class definitions
* *
* @var string $suffix * @var string $suffix
...@@ -72,7 +72,7 @@ class Doctrine_Builder_Record ...@@ -72,7 +72,7 @@ class Doctrine_Builder_Record
/** /**
* generateBaseClasses * generateBaseClasses
* *
* Bool true/false for whether or not to generate base classes * Bool true/false for whether or not to generate base classes
* *
* @var string $suffix * @var string $suffix
...@@ -81,20 +81,20 @@ class Doctrine_Builder_Record ...@@ -81,20 +81,20 @@ class Doctrine_Builder_Record
/** /**
* baseClassesDirectory * baseClassesDirectory
* *
* Directory to put the generate base classes in * Directory to put the generate base classes in
* *
* @var string $suffix * @var string $suffix
*/ */
protected $_baseClassesDirectory = 'generated'; protected $_baseClassesDirectory = 'generated';
/** /**
* baseClassName * baseClassName
* *
* @var string * @var string
*/ */
protected $_baseClassName = 'Doctrine_Record'; protected $_baseClassName = 'Doctrine_Record';
/** /**
* tpl * tpl
* *
...@@ -128,11 +128,11 @@ class Doctrine_Builder_Record ...@@ -128,11 +128,11 @@ class Doctrine_Builder_Record
$this->_path = $path; $this->_path = $path;
} }
/** /**
* setPackagePath * setPackagePath
* *
* @param string $packagesPrefix * @param string $packagesPrefix
* @return void * @return void
*/ */
public function setPackagesPrefix($packagesPrefix) public function setPackagesPrefix($packagesPrefix)
...@@ -143,14 +143,14 @@ class Doctrine_Builder_Record ...@@ -143,14 +143,14 @@ class Doctrine_Builder_Record
/** /**
* setPackagesPath * setPackagesPath
* *
* @param string $packagesPath * @param string $packagesPath
* @return void * @return void
*/ */
public function setPackagesPath($packagesPath) public function setPackagesPath($packagesPath)
{ {
$this->_packagesPath = $packagesPath; $this->_packagesPath = $packagesPath;
} }
/** /**
* generateBaseClasses * generateBaseClasses
* *
...@@ -177,7 +177,7 @@ class Doctrine_Builder_Record ...@@ -177,7 +177,7 @@ class Doctrine_Builder_Record
{ {
$this->_baseClassesDirectory; $this->_baseClassesDirectory;
} }
/** /**
* setBaseClassName * setBaseClassName
* *
...@@ -187,11 +187,11 @@ class Doctrine_Builder_Record ...@@ -187,11 +187,11 @@ class Doctrine_Builder_Record
{ {
$this->_baseClassName = $className; $this->_baseClassName = $className;
} }
/** /**
* setSuffix * setSuffix
* *
* @param string $suffix * @param string $suffix
* @return void * @return void
*/ */
public function setSuffix($suffix) public function setSuffix($suffix)
...@@ -212,7 +212,7 @@ class Doctrine_Builder_Record ...@@ -212,7 +212,7 @@ class Doctrine_Builder_Record
/** /**
* setOptions * setOptions
* *
* @param string $options * @param string $options
* @return void * @return void
*/ */
public function setOptions($options) public function setOptions($options)
...@@ -227,14 +227,14 @@ class Doctrine_Builder_Record ...@@ -227,14 +227,14 @@ class Doctrine_Builder_Record
/** /**
* setOption * setOption
* *
* @param string $key * @param string $key
* @param string $value * @param string $value
* @return void * @return void
*/ */
public function setOption($key, $value) public function setOption($key, $value)
{ {
$name = 'set' . Doctrine::classify($key); $name = 'set' . Doctrine::classify($key);
if (method_exists($this, $name)) { if (method_exists($this, $name)) {
$this->$name($value); $this->$name($value);
} else { } else {
...@@ -245,12 +245,12 @@ class Doctrine_Builder_Record ...@@ -245,12 +245,12 @@ class Doctrine_Builder_Record
/** /**
* loadTemplate * loadTemplate
* *
* Loads the class template used for generating classes * Loads the class template used for generating classes
* *
* @return void * @return void
*/ */
public function loadTemplate() public function loadTemplate()
{ {
if (isset(self::$_tpl)) { if (isset(self::$_tpl)) {
return; return;
...@@ -281,50 +281,50 @@ END; ...@@ -281,50 +281,50 @@ END;
if (isset($definition['inheritance']['type']) && ($definition['inheritance']['type'] == 'simple' || $definition['inheritance']['type'] == 'aggregation')) { if (isset($definition['inheritance']['type']) && ($definition['inheritance']['type'] == 'simple' || $definition['inheritance']['type'] == 'aggregation')) {
return; return;
} }
$ret = array(); $ret = array();
$i = 0; $i = 0;
if (isset($definition['inheritance']['extends']) && !(isset($definition['override_parent']) && $definition['override_parent'] == false)) { if (isset($definition['inheritance']['extends']) && !(isset($definition['override_parent']) && $definition['override_parent'] == false)) {
$ret[$i] = " parent::setTableDefinition();"; $ret[$i] = " parent::setTableDefinition();";
$i++; $i++;
} }
if (isset($definition['tableName']) && !empty($definition['tableName'])) { if (isset($definition['tableName']) && !empty($definition['tableName'])) {
$ret[$i] = " ".'$this->setTableName(\''. $definition['tableName'].'\');'; $ret[$i] = " ".'$this->setTableName(\''. $definition['tableName'].'\');';
$i++; $i++;
} }
if (isset($definition['columns']) && is_array($definition['columns']) && !empty($definition['columns'])) { if (isset($definition['columns']) && is_array($definition['columns']) && !empty($definition['columns'])) {
$ret[$i] = $this->buildColumns($definition['columns']); $ret[$i] = $this->buildColumns($definition['columns']);
$i++; $i++;
} }
if (isset($definition['indexes']) && is_array($definition['indexes']) && !empty($definition['indexes'])) { if (isset($definition['indexes']) && is_array($definition['indexes']) && !empty($definition['indexes'])) {
$ret[$i] = $this->buildIndexes($definition['indexes']); $ret[$i] = $this->buildIndexes($definition['indexes']);
$i++; $i++;
} }
if (isset($definition['attributes']) && is_array($definition['attributes']) && !empty($definition['attributes'])) { if (isset($definition['attributes']) && is_array($definition['attributes']) && !empty($definition['attributes'])) {
$ret[$i] = $this->buildAttributes($definition['attributes']); $ret[$i] = $this->buildAttributes($definition['attributes']);
$i++; $i++;
} }
if (isset($definition['options']) && is_array($definition['options']) && !empty($definition['options'])) { if (isset($definition['options']) && is_array($definition['options']) && !empty($definition['options'])) {
$ret[$i] = $this->buildOptions($definition['options']); $ret[$i] = $this->buildOptions($definition['options']);
$i++; $i++;
} }
if (isset($definition['subclasses']) && is_array($definition['subclasses']) && !empty($definition['subclasses'])) { if (isset($definition['subclasses']) && is_array($definition['subclasses']) && !empty($definition['subclasses'])) {
$ret[$i] = ' $this->setSubclasses(' . var_export($definition['subclasses'], true) . ');'; $ret[$i] = ' $this->setSubclasses(' . var_export($definition['subclasses'], true) . ');';
$i++; $i++;
} }
$code = implode("\n", $ret); $code = implode("\n", $ret);
$code = trim($code); $code = trim($code);
if ($code) { if ($code) {
return "\n public function setTableDefinition()"."\n {\n ".$code."\n }"; return "\n public function setTableDefinition()"."\n {\n ".$code."\n }";
} }
...@@ -333,21 +333,21 @@ END; ...@@ -333,21 +333,21 @@ END;
/** /**
* buildSetUp * buildSetUp
* *
* @param array $options * @param array $options
* @param array $columns * @param array $columns
* @param array $relations * @param array $relations
* @return string * @return string
*/ */
public function buildSetUp(array $definition) public function buildSetUp(array $definition)
{ {
$ret = array(); $ret = array();
$i = 0; $i = 0;
if (isset($definition['inheritance']['extends']) && !(isset($definition['override_parent']) && $definition['override_parent'] == false)) { if (isset($definition['inheritance']['extends']) && !(isset($definition['override_parent']) && $definition['override_parent'] == false)) {
$ret[$i] = " parent::setUp();"; $ret[$i] = " parent::setUp();";
$i++; $i++;
} }
if (isset($definition['relations']) && is_array($definition['relations']) && !empty($definition['relations'])) { if (isset($definition['relations']) && is_array($definition['relations']) && !empty($definition['relations'])) {
foreach ($definition['relations'] as $name => $relation) { foreach ($definition['relations'] as $name => $relation) {
$class = isset($relation['class']) ? $relation['class']:$name; $class = isset($relation['class']) ? $relation['class']:$name;
...@@ -357,49 +357,49 @@ END; ...@@ -357,49 +357,49 @@ END;
$relation['type'] = Doctrine_Relation::ONE; $relation['type'] = Doctrine_Relation::ONE;
} }
if ($relation['type'] === Doctrine_Relation::ONE || if ($relation['type'] === Doctrine_Relation::ONE ||
$relation['type'] === Doctrine_Relation::ONE_COMPOSITE) { $relation['type'] === Doctrine_Relation::ONE_COMPOSITE) {
$ret[$i] = " ".'$this->hasOne(\'' . $class . $alias . '\''; $ret[$i] = " ".'$this->hasOne(\'' . $class . $alias . '\'';
} else { } else {
$ret[$i] = " ".'$this->hasMany(\'' . $class . $alias . '\''; $ret[$i] = " ".'$this->hasMany(\'' . $class . $alias . '\'';
} }
$a = array(); $a = array();
if (isset($relation['refClass'])) { if (isset($relation['refClass'])) {
$a[] = '\'refClass\' => ' . var_export($relation['refClass'], true); $a[] = '\'refClass\' => ' . var_export($relation['refClass'], true);
} }
if (isset($relation['deferred']) && $relation['deferred']) { if (isset($relation['deferred']) && $relation['deferred']) {
$a[] = '\'default\' => ' . var_export($relation['deferred'], true); $a[] = '\'default\' => ' . var_export($relation['deferred'], true);
} }
if (isset($relation['local']) && $relation['local']) { if (isset($relation['local']) && $relation['local']) {
$a[] = '\'local\' => ' . var_export($relation['local'], true); $a[] = '\'local\' => ' . var_export($relation['local'], true);
} }
if (isset($relation['foreign']) && $relation['foreign']) { if (isset($relation['foreign']) && $relation['foreign']) {
$a[] = '\'foreign\' => ' . var_export($relation['foreign'], true); $a[] = '\'foreign\' => ' . var_export($relation['foreign'], true);
} }
if (isset($relation['onDelete']) && $relation['onDelete']) { if (isset($relation['onDelete']) && $relation['onDelete']) {
$a[] = '\'onDelete\' => ' . var_export($relation['onDelete'], true); $a[] = '\'onDelete\' => ' . var_export($relation['onDelete'], true);
} }
if (isset($relation['onUpdate']) && $relation['onUpdate']) { if (isset($relation['onUpdate']) && $relation['onUpdate']) {
$a[] = '\'onUpdate\' => ' . var_export($relation['onUpdate'], true); $a[] = '\'onUpdate\' => ' . var_export($relation['onUpdate'], true);
} }
if (isset($relation['equal']) && $relation['equal']) { if (isset($relation['equal']) && $relation['equal']) {
$a[] = '\'equal\' => ' . var_export($relation['equal'], true); $a[] = '\'equal\' => ' . var_export($relation['equal'], true);
} }
if ( ! empty($a)) { if ( ! empty($a)) {
$ret[$i] .= ', ' . 'array('; $ret[$i] .= ', ' . 'array(';
$length = strlen($ret[$i]); $length = strlen($ret[$i]);
$ret[$i] .= implode(',' . PHP_EOL . str_repeat(' ', $length), $a) . ')'; $ret[$i] .= implode(',' . PHP_EOL . str_repeat(' ', $length), $a) . ')';
} }
$ret[$i] .= ');'."\n"; $ret[$i] .= ');'."\n";
$i++; $i++;
} }
...@@ -426,7 +426,7 @@ END; ...@@ -426,7 +426,7 @@ END;
/** /**
* buildColumns * buildColumns
* *
* @param string $array * @param string $array
* @return void * @return void
*/ */
public function buildColumns(array $columns) public function buildColumns(array $columns)
...@@ -434,7 +434,7 @@ END; ...@@ -434,7 +434,7 @@ END;
$build = null; $build = null;
foreach ($columns as $name => $column) { foreach ($columns as $name => $column) {
$build .= " ".'$this->hasColumn(\'' . $name . '\', \'' . $column['type'] . '\''; $build .= " ".'$this->hasColumn(\'' . $name . '\', \'' . $column['type'] . '\'';
if ($column['length']) { if ($column['length']) {
$build .= ', ' . $column['length']; $build .= ', ' . $column['length'];
} else { } else {
...@@ -448,14 +448,14 @@ END; ...@@ -448,14 +448,14 @@ END;
unset($options[$key]); unset($options[$key]);
} }
} }
if (is_array($options) && !empty($options)) { if (is_array($options) && !empty($options)) {
$build .= ', ' . var_export($options, true); $build .= ', ' . var_export($options, true);
} }
$build .= ");\n"; $build .= ");\n";
} }
return $build; return $build;
} }
...@@ -471,11 +471,11 @@ END; ...@@ -471,11 +471,11 @@ END;
foreach (array_keys($definition['columns']) as $name) { foreach (array_keys($definition['columns']) as $name) {
$accessors[] = $name; $accessors[] = $name;
} }
foreach ($definition['relations'] as $relation) { foreach ($definition['relations'] as $relation) {
$accessors[] = $relation['alias']; $accessors[] = $relation['alias'];
} }
$ret = ''; $ret = '';
foreach ($accessors as $name) { foreach ($accessors as $name) {
// getters // getters
...@@ -497,17 +497,17 @@ END; ...@@ -497,17 +497,17 @@ END;
/** /**
* buildTemplates * buildTemplates
* *
* @param string $array * @param string $array
* @return void * @return void
*/ */
public function buildTemplates(array $templates) public function buildTemplates(array $templates)
{ {
$build = ''; $build = '';
foreach ($templates as $name => $options) { foreach ($templates as $name => $options) {
if (is_array($options) && !empty($options)) { if (is_array($options) && !empty($options)) {
$optionsPhp = var_export($options, true); $optionsPhp = var_export($options, true);
$build .= " \$this->loadTemplate('" . $name . "', " . $optionsPhp . ");\n"; $build .= " \$this->loadTemplate('" . $name . "', " . $optionsPhp . ");\n";
} else { } else {
if (isset($templates[0])) { if (isset($templates[0])) {
...@@ -517,14 +517,14 @@ END; ...@@ -517,14 +517,14 @@ END;
} }
} }
} }
return $build; return $build;
} }
/** /**
* buildActAs * buildActAs
* *
* @param string $array * @param string $array
* @return void * @return void
*/ */
public function buildActAs(array $actAs) public function buildActAs(array $actAs)
...@@ -533,7 +533,7 @@ END; ...@@ -533,7 +533,7 @@ END;
foreach ($actAs as $name => $options) { foreach ($actAs as $name => $options) {
if (is_array($options) && !empty($options)) { if (is_array($options) && !empty($options)) {
$optionsPhp = var_export($options, true); $optionsPhp = var_export($options, true);
$build .= " \$this->actAs('" . $name . "', " . $optionsPhp . ");\n"; $build .= " \$this->actAs('" . $name . "', " . $optionsPhp . ");\n";
} else { } else {
if (isset($actAs[0])) { if (isset($actAs[0])) {
...@@ -543,21 +543,21 @@ END; ...@@ -543,21 +543,21 @@ END;
} }
} }
} }
return $build; return $build;
} }
/** /**
* buildAttributes * buildAttributes
* *
* @param string $array * @param string $array
* @return void * @return void
*/ */
public function buildAttributes(array $attributes) public function buildAttributes(array $attributes)
{ {
$build = "\n"; $build = "\n";
foreach ($attributes as $key => $value) { foreach ($attributes as $key => $value) {
if (is_bool($value)) if (is_bool($value))
{ {
$values = $value ? 'true':'false'; $values = $value ? 'true':'false';
...@@ -565,26 +565,26 @@ END; ...@@ -565,26 +565,26 @@ END;
if ( ! is_array($value)) { if ( ! is_array($value)) {
$value = array($value); $value = array($value);
} }
$values = ''; $values = '';
foreach ($value as $attr) { foreach ($value as $attr) {
$values .= "Doctrine::" . strtoupper($key) . "_" . strtoupper($attr) . ' ^ '; $values .= "Doctrine::" . strtoupper($key) . "_" . strtoupper($attr) . ' ^ ';
} }
// Trim last ^ // Trim last ^
$values = substr($values, 0, strlen($values) - 3); $values = substr($values, 0, strlen($values) - 3);
} }
$build .= " \$this->setAttribute(Doctrine::ATTR_" . strtoupper($key) . ", " . $values . ");\n"; $build .= " \$this->setAttribute(Doctrine::ATTR_" . strtoupper($key) . ", " . $values . ");\n";
} }
return $build; return $build;
} }
/** /**
* buildTableOptions * buildTableOptions
* *
* @param string $array * @param string $array
* @return void * @return void
*/ */
public function buildOptions(array $options) public function buildOptions(array $options)
...@@ -593,14 +593,14 @@ END; ...@@ -593,14 +593,14 @@ END;
foreach ($options as $name => $value) { foreach ($options as $name => $value) {
$build .= " \$this->option('$name', " . var_export($value, true) . ");\n"; $build .= " \$this->option('$name', " . var_export($value, true) . ");\n";
} }
return $build; return $build;
} }
/** /**
* buildIndexes * buildIndexes
* *
* @param string $array * @param string $array
* @return void * @return void
*/ */
public function buildIndexes(array $indexes) public function buildIndexes(array $indexes)
...@@ -639,29 +639,29 @@ END; ...@@ -639,29 +639,29 @@ END;
$tableDefinitionCode = null; $tableDefinitionCode = null;
$setUpCode = null; $setUpCode = null;
} }
$accessorsCode = (isset($definition['generate_accessors']) && $definition['generate_accessors'] === true) ? $this->buildAccessors($definition):null; $accessorsCode = (isset($definition['generate_accessors']) && $definition['generate_accessors'] === true) ? $this->buildAccessors($definition):null;
$content = sprintf(self::$_tpl, $abstract, $content = sprintf(self::$_tpl, $abstract,
$className, $className,
$extends, $extends,
$tableDefinitionCode, $tableDefinitionCode,
$setUpCode, $setUpCode,
$accessorsCode); $accessorsCode);
return $content; return $content;
} }
/** /**
* buildRecord * buildRecord
* *
* @param array $options * @param array $options
* @param array $columns * @param array $columns
* @param array $relations * @param array $relations
* @param array $indexes * @param array $indexes
* @param array $attributes * @param array $attributes
* @param array $templates * @param array $templates
* @param array $actAs * @param array $actAs
* @return void= * @return void=
*/ */
public function buildRecord(array $definition) public function buildRecord(array $definition)
...@@ -672,19 +672,19 @@ END; ...@@ -672,19 +672,19 @@ END;
if ($this->generateBaseClasses()) { if ($this->generateBaseClasses()) {
$definition['is_package'] = (isset($definition['package']) && $definition['package']) ? true:false; $definition['is_package'] = (isset($definition['package']) && $definition['package']) ? true:false;
if ($definition['is_package']) { if ($definition['is_package']) {
$e = explode('.', $definition['package']); $e = explode('.', $definition['package']);
$definition['package_name'] = $e[0]; $definition['package_name'] = $e[0];
unset($e[0]); unset($e[0]);
$definition['package_path'] = implode(DIRECTORY_SEPARATOR, $e); $definition['package_path'] = implode(DIRECTORY_SEPARATOR, $e);
} }
// Top level definition that extends from all the others // Top level definition that extends from all the others
$topLevel = $definition; $topLevel = $definition;
unset($topLevel['tableName']); unset($topLevel['tableName']);
// If we have a package then we need to make this extend the package definition and not the base definition // If we have a package then we need to make this extend the package definition and not the base definition
// The package definition will then extends the base definition // The package definition will then extends the base definition
$topLevel['inheritance']['extends'] = (isset($topLevel['package']) && $topLevel['package']) ? $this->_packagesPrefix . $topLevel['className']:'Base' . $topLevel['className']; $topLevel['inheritance']['extends'] = (isset($topLevel['package']) && $topLevel['package']) ? $this->_packagesPrefix . $topLevel['className']:'Base' . $topLevel['className'];
...@@ -695,7 +695,7 @@ END; ...@@ -695,7 +695,7 @@ END;
// Package level definition that extends from the base definition // Package level definition that extends from the base definition
if (isset($definition['package'])) { if (isset($definition['package'])) {
$packageLevel = $definition; $packageLevel = $definition;
$packageLevel['className'] = $topLevel['inheritance']['extends']; $packageLevel['className'] = $topLevel['inheritance']['extends'];
$packageLevel['inheritance']['extends'] = 'Base' . $topLevel['className']; $packageLevel['inheritance']['extends'] = 'Base' . $topLevel['className'];
...@@ -714,11 +714,11 @@ END; ...@@ -714,11 +714,11 @@ END;
$baseClass['is_base_class'] = true; $baseClass['is_base_class'] = true;
$this->writeDefinition($baseClass); $this->writeDefinition($baseClass);
if (!empty($packageLevel)) { if (!empty($packageLevel)) {
$this->writeDefinition($packageLevel); $this->writeDefinition($packageLevel);
} }
$this->writeDefinition($topLevel); $this->writeDefinition($topLevel);
} else { } else {
$this->writeDefinition($definition); $this->writeDefinition($definition);
...@@ -728,13 +728,13 @@ END; ...@@ -728,13 +728,13 @@ END;
/** /**
* writeDefinition * writeDefinition
* *
* @param array $options * @param array $options
* @param array $columns * @param array $columns
* @param array $relations * @param array $relations
* @param array $indexes * @param array $indexes
* @param array $attributes * @param array $attributes
* @param array $templates * @param array $templates
* @param array $actAs * @param array $actAs
* @return void * @return void
*/ */
public function writeDefinition(array $definition) public function writeDefinition(array $definition)
...@@ -759,10 +759,10 @@ END; ...@@ -759,10 +759,10 @@ END;
// If is the package class then we need to make the path to the complete package // If is the package class then we need to make the path to the complete package
if (isset($definition['is_package_class']) && $definition['is_package_class']) { if (isset($definition['is_package_class']) && $definition['is_package_class']) {
$path = str_replace('.', DIRECTORY_SEPARATOR, trim($definition['package'])); $path = str_replace('.', DIRECTORY_SEPARATOR, trim($definition['package']));
$writePath = $packagesPath . DIRECTORY_SEPARATOR . $path; $writePath = $packagesPath . DIRECTORY_SEPARATOR . $path;
} }
// If it is the base class of the doctrine record definition // If it is the base class of the doctrine record definition
if (isset($definition['is_base_class']) && $definition['is_base_class']) { if (isset($definition['is_base_class']) && $definition['is_base_class']) {
// If it is a part of a package then we need to put it in a package subfolder // If it is a part of a package then we need to put it in a package subfolder
...@@ -776,11 +776,11 @@ END; ...@@ -776,11 +776,11 @@ END;
if (isset($writePath)) { if (isset($writePath)) {
Doctrine_Lib::makeDirectories($writePath); Doctrine_Lib::makeDirectories($writePath);
$writePath .= DIRECTORY_SEPARATOR . $fileName; $writePath .= DIRECTORY_SEPARATOR . $fileName;
} else { } else {
Doctrine_Lib::makeDirectories($this->_path); Doctrine_Lib::makeDirectories($this->_path);
$writePath = $this->_path . DIRECTORY_SEPARATOR . $fileName; $writePath = $this->_path . DIRECTORY_SEPARATOR . $fileName;
} }
...@@ -805,4 +805,4 @@ END; ...@@ -805,4 +805,4 @@ END;
throw new Doctrine_Builder_Exception("Couldn't write file " . $writePath); throw new Doctrine_Builder_Exception("Couldn't write file " . $writePath);
} }
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment