Commit d1df55e3 authored by Jonathan.Wage's avatar Jonathan.Wage

Refactorings for schema files and Doctrine_Record builder. More to come but...

Refactorings for schema files and Doctrine_Record builder. More to come but got held up on some things that zYne- must fix first.
parent 132e5c96
...@@ -192,6 +192,7 @@ final class Doctrine ...@@ -192,6 +192,7 @@ final class Doctrine
const ATTR_QUERY_CACHE = 157; const ATTR_QUERY_CACHE = 157;
const ATTR_QUERY_CACHE_LIFESPAN = 158; const ATTR_QUERY_CACHE_LIFESPAN = 158;
const ATTR_AUTOLOAD_TABLE_CLASSES = 160; const ATTR_AUTOLOAD_TABLE_CLASSES = 160;
const ATTR_MODEL_LOADING = 161;
/** /**
* LIMIT CONSTANTS * LIMIT CONSTANTS
...@@ -425,6 +426,23 @@ final class Doctrine ...@@ -425,6 +426,23 @@ final class Doctrine
*/ */
const IDENTIFIER_COMPOSITE = 4; const IDENTIFIER_COMPOSITE = 4;
/**
* MODEL_LOADING_AGRESSIVE
*
* Constant for agressive model loading
* Will require_once() all found model files
*/
const MODEL_LOADING_AGRESSIVE = 1;
/**
* MODEL_LOADING_CONSERVATIVE
*
* Constant for conservative model loading
* Will not require_once() found model files inititally instead it will build an array
* and reference it in autoload() when a class is needed it will require_once() it
*/
const MODEL_LOADING_CONSERVATIVE= 2;
/** /**
* Path * Path
* *
...@@ -505,10 +523,14 @@ final class Doctrine ...@@ -505,10 +523,14 @@ final class Doctrine
* Recursively load all models from a directory or array of directories * Recursively load all models from a directory or array of directories
* *
* @param string $directory Path to directory of models or array of directory paths * @param string $directory Path to directory of models or array of directory paths
* @param bool $aggressive Bool true/false for whether to load models aggressively.
* If true it will require_once() all found .php files
* @return array $loadedModels * @return array $loadedModels
*/ */
public static function loadModels($directory) public static function loadModels($directory, $agressive = true)
{ {
$loadedModels = array();
if ($directory !== null) { if ($directory !== null) {
$manager = Doctrine_Manager::getInstance(); $manager = Doctrine_Manager::getInstance();
...@@ -518,21 +540,14 @@ final class Doctrine ...@@ -518,21 +540,14 @@ final class Doctrine
foreach ($it as $file) { foreach ($it as $file) {
$e = explode('.', $file->getFileName()); $e = explode('.', $file->getFileName());
if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) { if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) {
self::$_loadedModelFiles[] = array(
'filename' => $e[0],
'filepath' => $file->getPathName()
);
}
}
}
$loadedModels = array();
$modelFiles = self::$_loadedModelFiles;
foreach ($modelFiles as $key => $model) { if ($manager->getAttribute(Doctrine::ATTR_MODEL_LOADING) == Doctrine::MODEL_LOADING_CONSERVATIVE) {
self::$_loadedModelFiles[$e[0]] = $file->getPathName();
$loadedModels[] = $e[0];
} else {
$declaredBefore = get_declared_classes(); $declaredBefore = get_declared_classes();
require_once $model['filepath']; require_once($file->getPathName());
$declaredAfter = get_declared_classes(); $declaredAfter = get_declared_classes();
// Using array_slice because array_diff is broken is some PHP versions // Using array_slice because array_diff is broken is some PHP versions
$foundClasses = array_slice($declaredAfter, count($declaredBefore) - 1); $foundClasses = array_slice($declaredAfter, count($declaredBefore) - 1);
...@@ -543,7 +558,9 @@ final class Doctrine ...@@ -543,7 +558,9 @@ final class Doctrine
} }
} }
} }
}
}
}
} }
} }
...@@ -567,6 +584,7 @@ final class Doctrine ...@@ -567,6 +584,7 @@ final class Doctrine
$classes = get_declared_classes(); $classes = get_declared_classes();
$classes = array_merge($classes, array_keys(self::$_loadedModelFiles)); $classes = array_merge($classes, array_keys(self::$_loadedModelFiles));
} }
return self::filterInvalidModels($classes); return self::filterInvalidModels($classes);
} }
......
...@@ -89,7 +89,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable ...@@ -89,7 +89,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
} }
switch ($attribute) { switch ($attribute) {
case Doctrine::ATTR_FETCHMODE: case Doctrine::ATTR_FETCHMODE:
throw new Doctrine_Exception('Deprecated attribute. See http://doctrine.pengus.net/doctrine/manual/new/?chapter=configuration'); throw new Doctrine_Exception('Deprecated attribute. See http://www.phpdoctrine.org/documentation/manual?chapter=configuration');
case Doctrine::ATTR_LISTENER: case Doctrine::ATTR_LISTENER:
$this->setEventListener($value); $this->setEventListener($value);
break; break;
...@@ -125,6 +125,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable ...@@ -125,6 +125,7 @@ abstract class Doctrine_Configurable extends Doctrine_Locator_Injectable
case Doctrine::ATTR_THROW_EXCEPTIONS: case Doctrine::ATTR_THROW_EXCEPTIONS:
case Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE: case Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE:
case Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES: case Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES:
case Doctrine::ATTR_MODEL_LOADING:
break; break;
case Doctrine::ATTR_SEQCOL_NAME: case Doctrine::ATTR_SEQCOL_NAME:
......
...@@ -130,9 +130,6 @@ class Doctrine_Data_Import extends Doctrine_Data ...@@ -130,9 +130,6 @@ class Doctrine_Data_Import extends Doctrine_Data
foreach ($row as $key => $value) { foreach ($row as $key => $value) {
if ($obj->getTable()->hasField($key)) { if ($obj->getTable()->hasField($key)) {
$obj->set($key, $value); $obj->set($key, $value);
} else if (method_exists($obj, 'set' . Doctrine::classify($key))) {
$func = 'set' . Doctrine::classify($key);
$obj->$func($value);
} else if ($obj->getTable()->hasRelation($key)) { } else if ($obj->getTable()->hasRelation($key)) {
if (is_array($value)) { if (is_array($value)) {
if (isset($value[0])) { if (isset($value[0])) {
...@@ -152,6 +149,9 @@ class Doctrine_Data_Import extends Doctrine_Data ...@@ -152,6 +149,9 @@ class Doctrine_Data_Import extends Doctrine_Data
} else { } else {
$obj->set($key, $this->_getImportedObject($value)); $obj->set($key, $this->_getImportedObject($value));
} }
} else if (method_exists($obj, 'set' . Doctrine::classify($key))) {
$func = 'set' . Doctrine::classify($key);
$obj->$func($value);
} }
} }
} }
......
...@@ -213,12 +213,14 @@ class Doctrine_Import extends Doctrine_Connection_Module ...@@ -213,12 +213,14 @@ class Doctrine_Import extends Doctrine_Connection_Module
$classes = array(); $classes = array();
foreach ($connection->import->listTables() as $table) { foreach ($connection->import->listTables() as $table) {
$builder->buildRecord(array('tableName' => $table, $definition = array();
'className' => Doctrine::classify($table)), $definition['tableName'] = $table;
$connection->import->listTableColumns($table), $definition['className'] = Doctrine_Inflector::classify($table);
array()); $definition['columns'] = $connection->import->listTableColumns($table);
$classes[] = Doctrine::classify($table); $builder->buildRecord($definition);
$classes[] = $definition['className'];
} }
} }
......
...@@ -79,13 +79,6 @@ class Doctrine_Import_Builder ...@@ -79,13 +79,6 @@ class Doctrine_Import_Builder
*/ */
protected $_generateBaseClasses = true; protected $_generateBaseClasses = true;
/**
* generateTableClasses
*
* @var string
*/
protected $_generateTableClasses = true;
/** /**
* baseClassesDirectory * baseClassesDirectory
* *
...@@ -175,23 +168,6 @@ class Doctrine_Import_Builder ...@@ -175,23 +168,6 @@ class Doctrine_Import_Builder
return $this->_generateBaseClasses; return $this->_generateBaseClasses;
} }
/**
* generateTableClasses
*
* Specify whether or not to generate table classes which extend from Doctrine_Table
*
* @param string $bool
* @return void
*/
public function generateTableClasses($bool = null)
{
if ($bool !== null) {
$this->_generateTableClasses = $bool;
}
return $this->_generateTableClasses;
}
/** /**
* setBaseClassesDirectory * setBaseClassesDirectory
* *
...@@ -294,102 +270,228 @@ END; ...@@ -294,102 +270,228 @@ END;
} }
/* /*
* Build the accessors * Build the table definition of a Doctrine_Record object
* *
* @param string $table * @param string $table
* @param array $columns * @param array $tableColumns
*/ */
public function buildAccessors(array $options, array $columns) public function buildTableDefinition(array $definition)
{ {
$ret = ''; // If the inheritance type if simple or column aggregation then we do not need a table definition
foreach ($columns as $name => $column) { if (isset($definition['inheritance']['type']) && ($definition['inheritance']['type'] == 'simple' || $definition['inheritance']['type'] == 'aggregation')) {
// getters return;
$ret .= "\n public function get".Doctrine::classify($name)."(\$load = true)\n"; }
$ret .= " {\n";
$ret .= " return \$this->get('{$name}', \$load);\n";
$ret .= " }\n";
// setters $ret = array();
$ret .= "\n public function set".Doctrine::classify($name)."(\${$name}, \$load = true)\n";
$ret .= " {\n"; $i = 0;
$ret .= " return \$this->set('{$name}', \${$name}, \$load);\n";
$ret .= " }\n"; if (isset($definition['inheritance']['extends']) && !(isset($definition['override_parent']) && $definition['override_parent'] == false)) {
$ret[$i] = " parent::setTableDefinition();";
$i++;
} }
return $ret; if (isset($definition['tableName']) && !empty($definition['tableName'])) {
$ret[$i] = " ".'$this->setTableName(\''. $definition['tableName'].'\');';
$i++;
} }
/* if (isset($definition['columns']) && is_array($definition['columns']) && !empty($definition['columns'])) {
* Build the table definition of a Doctrine_Record object $ret[$i] = $this->buildColumns($definition['columns']);
$i++;
}
if (isset($definition['indexes']) && is_array($definition['indexes']) && !empty($definition['indexes'])) {
$ret[$i] = $this->buildIndexes($definition['indexes']);
$i++;
}
if (isset($definition['attributes']) && is_array($definition['attributes']) && !empty($definition['attributes'])) {
$ret[$i] = $this->buildAttributes($definition['attributes']);
$i++;
}
if (isset($definition['options']) && is_array($definition['options']) && !empty($definition['options'])) {
$ret[$i] = $this->buildOptions($definition['options']);
$i++;
}
if (isset($definition['subclasses']) && is_array($definition['subclasses']) && !empty($definition['subclasses'])) {
$ret[$i] = ' $this->setSubclasses(' . var_export($definition['subclasses'], true) . ');';
$i++;
}
$code = implode("\n", $ret);
$code = trim($code);
if ($code) {
return "\n public function setTableDefinition()"."\n {\n ".$code."\n }";
}
}
/**
* buildSetUp
* *
* @param string $table * @param array $options
* @param array $tableColumns * @param array $columns
* @param array $relations
* @return string
*/ */
public function buildTableDefinition(array $options, array $columns, array $relations, array $indexes, array $attributes, array $tableOptions, array $templates, array $actAs) public function buildSetUp(array $definition)
{ {
$ret = array(); $ret = array();
$i = 0; $i = 0;
if (isset($options['inheritance']['extends']) && !(isset($options['override_parent']) && $options['override_parent'] == false)) { if (isset($definition['inheritance']['extends']) && !(isset($definition['override_parent']) && $definition['override_parent'] == false)) {
$ret[$i] = " parent::setTableDefinition();"; $ret[$i] = " parent::setUp();";
$i++; $i++;
} }
if (isset($options['tableName']) && !empty($options['tableName'])) { if (isset($definition['relations']) && is_array($definition['relations']) && !empty($definition['relations'])) {
$ret[$i] = " ".'$this->setTableName(\''. $options['tableName'].'\');'; foreach ($definition['relations'] as $name => $relation) {
$class = isset($relation['class']) ? $relation['class']:$name;
$alias = (isset($relation['alias']) && $relation['alias'] !== $relation['class']) ? ' as ' . $relation['alias'] : '';
$i++; if ( ! isset($relation['type'])) {
$relation['type'] = Doctrine_Relation::ONE;
} }
foreach ($columns as $name => $column) { if ($relation['type'] === Doctrine_Relation::ONE ||
$ret[$i] = " ".'$this->hasColumn(\'' . $name . '\', \'' . $column['type'] . '\''; $relation['type'] === Doctrine_Relation::ONE_COMPOSITE) {
$ret[$i] = " ".'$this->hasOne(\'' . $class . $alias . '\'';
if ($column['length']) {
$ret[$i] .= ', ' . $column['length'];
} else { } else {
$ret[$i] .= ', null'; $ret[$i] = " ".'$this->hasMany(\'' . $class . $alias . '\'';
} }
$options = $column; $a = array();
$unset = array('name', 'type', 'length', 'ptype');
foreach ($options as $key => $value) { if (isset($relation['refClass'])) {
if (in_array($key, $unset) || $value === null) { $a[] = '\'refClass\' => ' . var_export($relation['refClass'], true);
unset($options[$key]);
} }
if (isset($relation['deferred']) && $relation['deferred']) {
$a[] = '\'default\' => ' . var_export($relation['deferred'], true);
} }
$ret[$i] .= ', ' . var_export($options, true); if (isset($relation['local']) && $relation['local']) {
$a[] = '\'local\' => ' . var_export($relation['local'], true);
}
$ret[$i] .= ');'; if (isset($relation['foreign']) && $relation['foreign']) {
$a[] = '\'foreign\' => ' . var_export($relation['foreign'], true);
}
if ($i < (count($columns) - 1)) { if (isset($relation['onDelete']) && $relation['onDelete']) {
$ret[$i] .= PHP_EOL; $a[] = '\'onDelete\' => ' . var_export($relation['onDelete'], true);
} }
$i++;
if (isset($relation['onUpdate']) && $relation['onUpdate']) {
$a[] = '\'onUpdate\' => ' . var_export($relation['onUpdate'], true);
} }
$ret[$i] = $this->buildIndexes($indexes); if (isset($relation['equal']) && $relation['equal']) {
$i++; $a[] = '\'equal\' => ' . var_export($relation['equal'], true);
}
$ret[$i] = $this->buildAttributes($attributes); if ( ! empty($a)) {
$i++; $ret[$i] .= ', ' . 'array(';
$length = strlen($ret[$i]);
$ret[$i] .= implode(',' . PHP_EOL . str_repeat(' ', $length), $a) . ')';
}
$ret[$i] = $this->buildTableOptions($tableOptions); $ret[$i] .= ');'."\n";
$i++; $i++;
}
}
$ret[$i] = $this->buildTemplates($templates); if (isset($definition['templates']) && is_array($definition['templates']) && !empty($definition['templates'])) {
$ret[$i] = $this->buildTemplates($definition['templates']);
$i++; $i++;
}
$ret[$i] = $this->buildActAs($actAs); if (isset($definition['actAs']) && is_array($definition['actAs']) && !empty($definition['actAs'])) {
$ret[$i] = $this->buildActAs($definition['actAs']);
$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 setUp()\n {\n ".$code."\n }";
}
}
/**
* buildColumns
*
* @param string $array
* @return void
*/
public function buildColumns(array $columns)
{
$build = null;
foreach ($columns as $name => $column) {
$build .= " ".'$this->hasColumn(\'' . $name . '\', \'' . $column['type'] . '\'';
if ($column['length']) {
$build .= ', ' . $column['length'];
} else {
$build .= ', null';
}
$options = $column;
$unset = array('name', 'type', 'length', 'ptype');
foreach ($options as $key => $value) {
if (in_array($key, $unset) || $value === null) {
unset($options[$key]);
}
}
if (is_array($options) && !empty($options)) {
$build .= ', ' . var_export($options, true);
} }
$build .= ");\n";
}
return $build;
}
/*
* Build the accessors
*
* @param string $table
* @param array $columns
*/
public function buildAccessors(array $definition)
{
$accessors = array();
foreach (array_keys($definition['columns']) as $name) {
$accessors[] = $name;
}
foreach ($definition['relations'] as $relation) {
$accessors[] = $relation['alias'];
}
$ret = '';
foreach ($accessors as $name) {
// getters
$ret .= "\n public function get" . Doctrine_Inflector::classify(Doctrine_Inflector::tableize($name)) . "(\$load = true)\n";
$ret .= " {\n";
$ret .= " return \$this->get('{$name}', \$load);\n";
$ret .= " }\n";
// setters
$ret .= "\n public function set" . Doctrine_Inflector::classify(Doctrine_Inflector::tableize($name)) . "(\${$name}, \$load = true)\n";
$ret .= " {\n";
$ret .= " return \$this->set('{$name}', \${$name}, \$load);\n";
$ret .= " }\n";
}
return $ret;
} }
/** /**
...@@ -485,7 +587,7 @@ END; ...@@ -485,7 +587,7 @@ END;
* @param string $array * @param string $array
* @return void * @return void
*/ */
public function buildTableOptions(array $options) public function buildOptions(array $options)
{ {
$build = ''; $build = '';
foreach ($options as $name => $value) { foreach ($options as $name => $value) {
...@@ -514,130 +616,38 @@ END; ...@@ -514,130 +616,38 @@ END;
return $build; return $build;
} }
/**
* buildSetUp
*
* @param array $options
* @param array $columns
* @param array $relations
* @return string
*/
public function buildSetUp(array $options, array $columns, array $relations, array $templates, array $actAs)
{
$ret = array();
$i = 0;
if (isset($options['inheritance']['extends']) && !(isset($options['override_parent']) && $options['override_parent'] == false)) {
$ret[$i] = " parent::setUp();";
$i++;
}
foreach ($relations as $name => $relation) {
$class = isset($relation['class']) ? $relation['class']:$name;
$alias = (isset($relation['alias']) && $relation['alias'] !== $relation['class']) ? ' as ' . $relation['alias'] : '';
if ( ! isset($relation['type'])) {
$relation['type'] = Doctrine_Relation::ONE;
}
if ($relation['type'] === Doctrine_Relation::ONE ||
$relation['type'] === Doctrine_Relation::ONE_COMPOSITE) {
$ret[$i] = " ".'$this->hasOne(\'' . $class . $alias . '\'';
} else {
$ret[$i] = " ".'$this->hasMany(\'' . $class . $alias . '\'';
}
$a = array();
if (isset($relation['refClass'])) {
$a[] = '\'refClass\' => ' . var_export($relation['refClass'], true);
}
if (isset($relation['deferred']) && $relation['deferred']) {
$a[] = '\'default\' => ' . var_export($relation['deferred'], true);
}
if (isset($relation['local']) && $relation['local']) {
$a[] = '\'local\' => ' . var_export($relation['local'], true);
}
if (isset($relation['foreign']) && $relation['foreign']) {
$a[] = '\'foreign\' => ' . var_export($relation['foreign'], true);
}
if (isset($relation['onDelete']) && $relation['onDelete']) {
$a[] = '\'onDelete\' => ' . var_export($relation['onDelete'], true);
}
if (isset($relation['onUpdate']) && $relation['onUpdate']) {
$a[] = '\'onUpdate\' => ' . var_export($relation['onUpdate'], true);
}
if (isset($relation['equal']) && $relation['equal']) {
$a[] = '\'equal\' => ' . var_export($relation['equal'], true);
}
if ( ! empty($a)) {
$ret[$i] .= ', ' . 'array(';
$length = strlen($ret[$i]);
$ret[$i] .= implode(',' . PHP_EOL . str_repeat(' ', $length), $a) . ')';
}
$ret[$i] .= ');'."\n";
$i++;
}
if (isset($options['inheritance']['keyField']) && isset($options['inheritance']['keyValue'])) {
$i++;
$ret[$i] = " ".'$this->setInheritanceMap(array(\''.$options['inheritance']['keyField'].'\' => \''.$options['inheritance']['keyValue'].'\'));';
}
$code = implode("\n", $ret);
$code = trim($code);
if ($code) {
return "\n public function setUp()\n {\n ".$code."\n }";
}
}
/** /**
* buildDefinition * buildDefinition
* *
* @param array $options * @param array $definition
* @param array $columns
* @param array $relations
* @param array $indexes
* @param array $attributes
* @param array $templates
* @param array $actAs
* @return string * @return string
*/ */
public function buildDefinition(array $options, array $columns, array $relations = array(), array $indexes = array(), $attributes = array(), array $templates = array(), array $actAs = array(), array $tableOptions = array()) public function buildDefinition(array $definition)
{ {
if ( ! isset($options['className'])) { if ( ! isset($definition['className'])) {
throw new Doctrine_Import_Builder_Exception('Missing class name.'); throw new Doctrine_Import_Builder_Exception('Missing class name.');
} }
$abstract = isset($options['abstract']) && $options['abstract'] === true ? 'abstract ':null; $abstract = isset($definition['abstract']) && $definition['abstract'] === true ? 'abstract ':null;
$className = $options['className']; $className = $definition['className'];
$extends = isset($options['inheritance']['extends']) ? $options['inheritance']['extends']:$this->_baseClassName; $extends = isset($definition['inheritance']['extends']) ? $definition['inheritance']['extends']:$this->_baseClassName;
if ( ! (isset($options['no_definition']) && $options['no_definition'] === true)) { if ( ! (isset($definition['no_definition']) && $definition['no_definition'] === true)) {
$definition = $this->buildTableDefinition($options, $columns, $relations, $indexes, $attributes, $tableOptions, $templates, $actAs); $tableDefinitionCode = $this->buildTableDefinition($definition);
$setUp = $this->buildSetUp($options, $columns, $relations, $templates, $actAs); $setUpCode = $this->buildSetUp($definition);
} else { } else {
$definition = null; $tableDefinitionCode = null;
$setUp = null; $setUpCode = null;
} }
$accessors = (isset($options['generate_accessors']) && $options['generate_accessors'] === true) ? $this->buildAccessors($options, $columns):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,
$definition, $tableDefinitionCode,
$setUp, $setUpCode,
$accessors); $accessorsCode);
return $content; return $content;
} }
...@@ -654,25 +664,25 @@ END; ...@@ -654,25 +664,25 @@ END;
* @param array $actAs * @param array $actAs
* @return void= * @return void=
*/ */
public function buildRecord(array $options, array $columns, array $relations = array(), array $indexes = array(), array $attributes = array(), array $templates = array(), array $actAs = array(), array $tableOptions = array()) public function buildRecord(array $definition)
{ {
if ( !isset($options['className'])) { if ( !isset($definition['className'])) {
throw new Doctrine_Import_Builder_Exception('Missing class name.'); throw new Doctrine_Import_Builder_Exception('Missing class name.');
} }
if ($this->generateBaseClasses()) { if ($this->generateBaseClasses()) {
$options['is_package'] = (isset($options['package']) && $options['package']) ? true:false; $definition['is_package'] = (isset($definition['package']) && $definition['package']) ? true:false;
if ($options['is_package']) { if ($definition['is_package']) {
$e = explode('.', $options['package']); $e = explode('.', $definition['package']);
$options['package_name'] = $e[0]; $definition['package_name'] = $e[0];
unset($e[0]); unset($e[0]);
$options['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 = $options; $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
...@@ -684,9 +694,9 @@ END; ...@@ -684,9 +694,9 @@ END;
unset($topLevel['connection']); unset($topLevel['connection']);
// Package level definition that extends from the base definition // Package level definition that extends from the base definition
if (isset($options['package'])) { if (isset($definition['package'])) {
$packageLevel = $options; $packageLevel = $definition;
$packageLevel['className'] = $topLevel['inheritance']['extends']; $packageLevel['className'] = $topLevel['inheritance']['extends'];
$packageLevel['inheritance']['extends'] = 'Base' . $topLevel['className']; $packageLevel['inheritance']['extends'] = 'Base' . $topLevel['className'];
$packageLevel['no_definition'] = true; $packageLevel['no_definition'] = true;
...@@ -697,13 +707,13 @@ END; ...@@ -697,13 +707,13 @@ END;
unset($packageLevel['connection']); unset($packageLevel['connection']);
} }
$baseClass = $options; $baseClass = $definition;
$baseClass['className'] = 'Base' . $baseClass['className']; $baseClass['className'] = 'Base' . $baseClass['className'];
$baseClass['abstract'] = true; $baseClass['abstract'] = true;
$baseClass['override_parent'] = true; $baseClass['override_parent'] = true;
$baseClass['is_base_class'] = true; $baseClass['is_base_class'] = true;
$this->writeDefinition($baseClass, $columns, $relations, $indexes, $attributes, $templates, $actAs, $tableOptions); $this->writeDefinition($baseClass);
if (!empty($packageLevel)) { if (!empty($packageLevel)) {
$this->writeDefinition($packageLevel); $this->writeDefinition($packageLevel);
...@@ -711,34 +721,7 @@ END; ...@@ -711,34 +721,7 @@ END;
$this->writeDefinition($topLevel); $this->writeDefinition($topLevel);
} else { } else {
$this->writeDefinition($options, $columns, $relations, $indexes, $attributes, $templates, $actAs, $tableOptions); $this->writeDefinition($definition);
}
}
/**
* writeTableDefinition
*
* @return void
*/
public function writeTableDefinition($className, $path, $options = array())
{
$className = $className . 'Table';
$content = '<?php' . PHP_EOL;
$content .= sprintf(self::$_tpl, false,
$className,
isset($options['extends']) ? $options['extends']:'Doctrine_Table',
null,
null,
null
);
Doctrine_Lib::makeDirectories($path);
$writePath = $path . DIRECTORY_SEPARATOR . $className . $this->_suffix;
if (!file_exists($writePath)) {
file_put_contents($writePath, $content);
} }
} }
...@@ -754,43 +737,37 @@ END; ...@@ -754,43 +737,37 @@ END;
* @param array $actAs * @param array $actAs
* @return void * @return void
*/ */
public function writeDefinition(array $options, array $columns = array(), array $relations = array(), array $indexes = array(), array $attributes = array(), array $templates = array(), array $actAs = array(), array $tableOptions = array()) public function writeDefinition(array $definition)
{ {
$definition = $this->buildDefinition($options, $columns, $relations, $indexes, $attributes, $templates, $actAs, $tableOptions); $definitionCode = $this->buildDefinition($definition);
$fileName = $options['className'] . $this->_suffix; $fileName = $definition['className'] . $this->_suffix;
$packagesPath = $this->_packagesPath ? $this->_packagesPath:$this->_path; $packagesPath = $this->_packagesPath ? $this->_packagesPath:$this->_path;
// If this is a main class that either extends from Base or Package class // If this is a main class that either extends from Base or Package class
if (isset($options['is_main_class']) && $options['is_main_class']) { if (isset($definition['is_main_class']) && $definition['is_main_class']) {
// If is package then we need to put it in a package subfolder // If is package then we need to put it in a package subfolder
if (isset($options['is_package']) && $options['is_package']) { if (isset($definition['is_package']) && $definition['is_package']) {
$writePath = $this->_path . DIRECTORY_SEPARATOR . $options['package_name']; $writePath = $this->_path . DIRECTORY_SEPARATOR . $definition['package_name'];
$this->writeTableDefinition($options['className'], $writePath, array('extends' => $options['inheritance']['extends'] . 'Table'));
// Otherwise lets just put it in the root of the path // Otherwise lets just put it in the root of the path
} else { } else {
$writePath = $this->_path; $writePath = $this->_path;
$this->writeTableDefinition($options['className'], $writePath);
} }
} }
// 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($options['is_package_class']) && $options['is_package_class']) { if (isset($definition['is_package_class']) && $definition['is_package_class']) {
$path = str_replace('.', DIRECTORY_SEPARATOR, trim($options['package'])); $path = str_replace('.', DIRECTORY_SEPARATOR, trim($definition['package']));
$writePath = $packagesPath . DIRECTORY_SEPARATOR . $path; $writePath = $packagesPath . DIRECTORY_SEPARATOR . $path;
$this->writeTableDefinition($options['className'], $writePath);
} }
// If it is the base class of the doctrine record definition // If it is the base class of the doctrine record definition
if (isset($options['is_base_class']) && $options['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
if (isset($options['is_package']) && $options['is_package']) { if (isset($definition['is_package']) && $definition['is_package']) {
$writePath = $this->_path . DIRECTORY_SEPARATOR . $options['package_name'] . DIRECTORY_SEPARATOR . $this->_baseClassesDirectory; $writePath = $this->_path . DIRECTORY_SEPARATOR . $definition['package_name'] . DIRECTORY_SEPARATOR . $this->_baseClassesDirectory;
// Otherwise lets just put it in the root generated folder // Otherwise lets just put it in the root generated folder
} else { } else {
$writePath = $this->_path . DIRECTORY_SEPARATOR . $this->_baseClassesDirectory; $writePath = $this->_path . DIRECTORY_SEPARATOR . $this->_baseClassesDirectory;
...@@ -809,14 +786,14 @@ END; ...@@ -809,14 +786,14 @@ END;
$code = "<?php" . PHP_EOL; $code = "<?php" . PHP_EOL;
if (isset($options['connection']) && $options['connection']) { if (isset($definition['connection']) && $definition['connection']) {
$code .= "// Connection Component Binding\n"; $code .= "// Connection Component Binding\n";
$code .= "Doctrine_Manager::getInstance()->bindComponent('" . $options['connectionClassName'] . "', '" . $options['connection'] . "');\n"; $code .= "Doctrine_Manager::getInstance()->bindComponent('" . $definition['connectionClassName'] . "', '" . $definition['connection'] . "');\n";
} }
$code .= PHP_EOL . $definition; $code .= PHP_EOL . $definitionCode;
if (isset($options['generate_once']) && $options['generate_once'] === true) { if (isset($definition['generate_once']) && $definition['generate_once'] === true) {
if (!file_exists($writePath)) { if (!file_exists($writePath)) {
$bytes = file_put_contents($writePath, $code); $bytes = file_put_contents($writePath, $code);
} }
......
...@@ -43,7 +43,6 @@ class Doctrine_Import_Schema ...@@ -43,7 +43,6 @@ class Doctrine_Import_Schema
protected $_options = array('packagesPrefix' => 'Package', protected $_options = array('packagesPrefix' => 'Package',
'packagesPath' => '', 'packagesPath' => '',
'generateBaseClasses' => true, 'generateBaseClasses' => true,
'generateTableClasses' => true,
'baseClassesDirectory' => 'generated', 'baseClassesDirectory' => 'generated',
'baseClassName' => 'Doctrine_Record', 'baseClassName' => 'Doctrine_Record',
'suffix' => '.php'); 'suffix' => '.php');
...@@ -61,6 +60,16 @@ class Doctrine_Import_Schema ...@@ -61,6 +60,16 @@ class Doctrine_Import_Schema
} }
} }
/**
* getOptions
*
* @return void
*/
public function getOptions()
{
return $this->_options;
}
/** /**
* setOption * setOption
* *
...@@ -119,7 +128,7 @@ class Doctrine_Import_Schema ...@@ -119,7 +128,7 @@ class Doctrine_Import_Schema
} }
} }
$this->_buildRelationships($array); $array = $this->_buildRelationships($array);
return $array; return $array;
} }
...@@ -139,175 +148,76 @@ class Doctrine_Import_Schema ...@@ -139,175 +148,76 @@ class Doctrine_Import_Schema
{ {
$builder = new Doctrine_Import_Builder(); $builder = new Doctrine_Import_Builder();
$builder->setTargetPath($directory); $builder->setTargetPath($directory);
$builder->setOptions($this->getOptions());
foreach ($this->_options as $key => $value) {
if ($value) {
$builder->setOption($key, $value);
}
}
$array = $this->buildSchema($schema, $format); $array = $this->buildSchema($schema, $format);
foreach ($array as $name => $properties) { foreach ($array as $name => $definition) {
if ( ! empty($models) && !in_array($properties['className'], $models)) { if ( ! empty($models) && !in_array($definition['className'], $models)) {
continue; continue;
} }
$options = $this->getOptions($properties); $builder->buildRecord($definition);
$columns = $this->getColumns($properties);
$relations = $this->getRelations($properties);
$indexes = $this->getIndexes($properties);
$attributes = $this->getAttributes($properties);
$templates = $this->getTemplates($properties);
$actAs = $this->getActAs($properties);
$tableOptions = $this->getTableOptions($properties);
$builder->buildRecord($options, $columns, $relations, $indexes, $attributes, $templates, $actAs, $tableOptions);
} }
} }
/** /**
* getOptions * parseSchema
*
* @param string $properties Array of table properties
* @param string $directory Directory we are writing the class to
* @return array $options Array of options from a parse schemas properties
*/
public function getOptions($properties)
{
$options = array();
$options['className'] = $properties['className'];
$options['tableName'] = isset($properties['tableName']) ? $properties['tableName']:null;
$options['connection'] = isset($properties['connection']) ? $properties['connection']:null;
$options['connectionClassName'] = isset($properties['connection']) ? $properties['className']:null;
$options['package'] = $properties['package'];
if (isset($properties['inheritance'])) {
$options['inheritance'] = $properties['inheritance'];
}
return $options;
}
/**
* getColumns
*
* Get array of columns from table properties
*
* @param string $properties Array of table properties
* @return array $columns Array of columns
*/
public function getColumns($properties)
{
return isset($properties['columns']) ? $properties['columns']:array();
}
/**
* getRelations
* *
* Get array of relations from table properties * A method to parse a Schema and translate it into a property array.
* The function returns that property array.
* *
* @param string $properties Array of tables properties * @param string $schema Path to the file containing the schema
* @return array $relations Array of relations * @return array $build Built array of schema information
*/ */
public function getRelations($properties) public function parseSchema($schema, $type)
{ {
$allRelations = isset($this->_relations[$properties['className']]) ? $this->_relations[$properties['className']]:array(); $defaults = array('className' => null,
'tableName' => null,
'connection' => null,
'relations' => array(),
'indexes' => array(),
'attributes' => array(),
'templates' => array(),
'actAs' => array(),
'options' => array(),
'package' => null,
'inheritance' => array(),
'subclasses' => array(),
'detect_relations' => false,
'generate_accessors' => false);
// This is for checking for duplicates between alias-relations and a auto-generated relations to ensure the result set of unique relations $array = Doctrine_Parser::load($schema, $type);
$existingRelations = array();
$uniqueRelations = array();
foreach ($allRelations as $relation) {
if ( ! in_array($relation['key'], $existingRelations)) {
$existingRelations[] = $relation['key'];
$uniqueRelations = array_merge($uniqueRelations, array($relation['alias'] => $relation));
} else {
// check to see if this relationship is not autogenerated, if it's not, then the user must have explicitly declared it
if (!isset($relation['autogenerated']) || $relation['autogenerated'] != true) {
$uniqueRelations = array_merge($uniqueRelations, array($relation['alias'] => $relation));
}
}
}
return $uniqueRelations; // Go through the schema and look for global values so we can assign them to each table/class
} $globals = array();
$globalKeys = array('connection',
'attributes',
'templates',
'actAs',
'options',
'package',
'inheritance',
'detect_relations',
'generate_accessors');
/** // Loop over and build up all the global values and remove them from the array
* getIndexes foreach ($array as $key => $value) {
* if (in_array($key, $globalKeys)) {
* Get array of indexes from table properties unset($array[$key]);
* $globals[$key] = $value;
* @param string $properties Array of table properties
* @return array $index
*/
public function getIndexes($properties)
{
return isset($properties['indexes']) ? $properties['indexes']:array();;
} }
/**
* getAttributes
*
* Get array of attributes from table properties
*
* @param string $properties Array of tables properties
* @return array $attributes
*/
public function getAttributes($properties)
{
return isset($properties['attributes']) ? $properties['attributes']:array();
} }
/** // Apply the globals to each table if it does not have a custom value set already
* getTemplates foreach ($array as $className => $table) {
* foreach ($globals as $key => $value) {
* Get array of templates from table properties if (!isset($array[$className][$key])) {
* $array[$className][$key] = $value;
* @param string $properties Array of table properties
* @return array $templates Array of table templates
*/
public function getTemplates($properties)
{
return isset($properties['templates']) ? $properties['templates']:array();
} }
/**
* getActAs
*
* Get array of actAs definitions from table properties
*
* @param string $properties Array of table properties
* @return array $actAs Array of actAs definitions from table properties
*/
public function getActAs($properties)
{
return isset($properties['actAs']) ? $properties['actAs']:array();
} }
/**
* getTableOptions
*
* @param string $properties
* @return void
*/
public function getTableOptions($properties)
{
return isset($properties['options']) ? $properties['options']:array();
} }
/**
* parseSchema
*
* A method to parse a Schema and translate it into a property array.
* The function returns that property array.
*
* @param string $schema Path to the file containing the schema
* @return array $build Built array of schema information
*/
public function parseSchema($schema, $type)
{
$array = Doctrine_Parser::load($schema, $type);
$build = array(); $build = array();
foreach ($array as $className => $table) { foreach ($array as $className => $table) {
...@@ -318,7 +228,7 @@ class Doctrine_Import_Schema ...@@ -318,7 +228,7 @@ class Doctrine_Import_Schema
if (isset($table['tableName']) && $table['tableName']) { if (isset($table['tableName']) && $table['tableName']) {
$tableName = $table['tableName']; $tableName = $table['tableName'];
} else { } else {
if (isset($table['inheritance']['extends']) && isset($table['inheritance']['extends']['keyType']) && isset($table['inheritance']['extends']['keyValue'])) { if (isset($table['inheritance']['extends'])) {
$tableName = null; $tableName = null;
} else { } else {
$tableName = Doctrine::tableize($className); $tableName = Doctrine::tableize($className);
...@@ -326,13 +236,20 @@ class Doctrine_Import_Schema ...@@ -326,13 +236,20 @@ class Doctrine_Import_Schema
} }
$columns = isset($table['columns']) ? $table['columns']:array(); $columns = isset($table['columns']) ? $table['columns']:array();
$columns = isset($table['fields']) ? $table['fields']:$columns;
if ( ! empty($columns)) { if ( ! empty($columns)) {
foreach ($columns as $columnName => $field) { foreach ($columns as $columnName => $field) {
// Support short syntax: my_column: integer(4)
if (!is_array($field)) {
$original = $field;
$field = array();
$field['type'] = $original;
}
$colDesc = array(); $colDesc = array();
$colDesc['name'] = $columnName; $colDesc['name'] = $columnName;
// Support short type(length) syntax: my_column: { type: integer(4) }
$e = explode('(', $field['type']); $e = explode('(', $field['type']);
if (isset($e[0]) && isset($e[1])) { if (isset($e[0]) && isset($e[1])) {
$colDesc['type'] = $e[0]; $colDesc['type'] = $e[0];
...@@ -343,15 +260,14 @@ class Doctrine_Import_Schema ...@@ -343,15 +260,14 @@ class Doctrine_Import_Schema
$colDesc['length'] = isset($field['size']) ? (int) $field['size']:$colDesc['length']; $colDesc['length'] = isset($field['size']) ? (int) $field['size']:$colDesc['length'];
} }
$colDesc['ptype'] = isset($field['ptype']) ? (string) $field['ptype']:(string) $colDesc['type'];
$colDesc['fixed'] = isset($field['fixed']) ? (int) $field['fixed']:null; $colDesc['fixed'] = isset($field['fixed']) ? (int) $field['fixed']:null;
$colDesc['primary'] = isset($field['primary']) ? (bool) (isset($field['primary']) && $field['primary']):null; $colDesc['primary'] = isset($field['primary']) ? (bool) (isset($field['primary']) && $field['primary']):null;
$colDesc['default'] = isset($field['default']) ? $field['default']:null; $colDesc['default'] = isset($field['default']) ? $field['default']:null;
$colDesc['autoincrement'] = isset($field['autoincrement']) ? (bool) (isset($field['autoincrement']) && $field['autoincrement']):null; $colDesc['autoincrement'] = isset($field['autoincrement']) ? (bool) (isset($field['autoincrement']) && $field['autoincrement']):null;
$colDesc['autoincrement'] = isset($field['autoinc']) ? (bool) (isset($field['autoinc']) && $field['autoinc']):$colDesc['autoincrement'];
$colDesc['sequence'] = isset($field['sequence']) ? (string) $field['sequence']:null; $colDesc['sequence'] = isset($field['sequence']) ? (string) $field['sequence']:null;
$colDesc['values'] = isset($field['values']) ? (array) $field['values']:null; $colDesc['values'] = isset($field['values']) ? (array) $field['values']:null;
// Include all the specified and valid validators in the colDesc
$validators = Doctrine_Lib::getValidators(); $validators = Doctrine_Lib::getValidators();
foreach ($validators as $validator) { foreach ($validators as $validator) {
...@@ -364,21 +280,24 @@ class Doctrine_Import_Schema ...@@ -364,21 +280,24 @@ class Doctrine_Import_Schema
} }
} }
$build[$className]['connection'] = isset($table['connection']) ? $table['connection']:null; // Apply the default values
foreach ($defaults as $key => $defaultValue) {
if (isset($table[$key]) && !isset($build[$className][$key])) {
$build[$className][$key] = $table[$key];
} else {
$build[$className][$key] = isset($build[$className][$key]) ? $build[$className][$key]:$defaultValue;
}
}
$build[$className]['className'] = $className; $build[$className]['className'] = $className;
$build[$className]['tableName'] = $tableName; $build[$className]['tableName'] = $tableName;
$build[$className]['columns'] = $columns; $build[$className]['columns'] = $columns;
$build[$className]['relations'] = isset($table['relations']) ? $table['relations']:array();
$build[$className]['indexes'] = isset($table['indexes']) ? $table['indexes']:array();
$build[$className]['attributes'] = isset($table['attributes']) ? $table['attributes']:array();
$build[$className]['templates'] = isset($table['templates']) ? $table['templates']:array();
$build[$className]['actAs'] = isset($table['actAs']) ? $table['actAs']:array();
$build[$className]['options'] = isset($table['options']) ? $table['options']:array();
$build[$className]['package'] = isset($table['package']) ? $table['package']:null;
if (isset($table['inheritance'])) { // Make sure that anything else that is specified in the schema makes it to the final array
$build[$className]['inheritance'] = $table['inheritance']; $build[$className] = Doctrine_Lib::arrayDeepMerge($table, $build[$className]);
}
// We need to keep track of the className for the connection
$build[$className]['connectionClassName'] = $build[$className]['className'];
} }
return $build; return $build;
...@@ -395,6 +314,19 @@ class Doctrine_Import_Schema ...@@ -395,6 +314,19 @@ class Doctrine_Import_Schema
*/ */
protected function _buildRelationships($array) protected function _buildRelationships($array)
{ {
// Handle auto detecting relations by the names of columns
// User.contact_id will automatically create User hasOne Contact local => contact_id, foreign => id
foreach ($array as $className => $properties) {
if (isset($properties['columns']) && !empty($properties['columns']) && isset($properties['detect_relations']) && $properties['detect_relations']) {
foreach ($properties['columns'] as $column) {
$columnClassName = Doctrine_Inflector::classify(str_replace('_id', '', $column['name']));
if (isset($array[$columnClassName]) && !isset($array[$className]['relations'][$columnClassName])) {
$array[$className]['relations'][$columnClassName] = array();
}
}
}
}
foreach ($array as $name => $properties) { foreach ($array as $name => $properties) {
if ( ! isset($properties['relations'])) { if ( ! isset($properties['relations'])) {
continue; continue;
...@@ -438,18 +370,28 @@ class Doctrine_Import_Schema ...@@ -438,18 +370,28 @@ class Doctrine_Import_Schema
} }
} }
// Now we fix all the relationships and auto-complete opposite ends of relationships // Now we auto-complete opposite ends of relationships
$this->_fixRelationships(); $this->_autoCompleteOppositeRelations();
// Make sure we do not have any duplicate relations
$this->_fixDuplicateRelations();
foreach ($this->_relations as $className => $relations) {
$array[$className]['relations'] = $relations;
}
return $array;
} }
/** /**
* fixRelationships * fixRelationships
* *
* Loop through all relationships building the opposite ends of each relationship * Loop through all relationships building the opposite ends of each relationship
* and make sure no duplicate relations exist
* *
* @return void * @return void
*/ */
protected function _fixRelationships() protected function _autoCompleteOppositeRelations()
{ {
foreach($this->_relations as $className => $relations) { foreach($this->_relations as $className => $relations) {
foreach ($relations AS $alias => $relation) { foreach ($relations AS $alias => $relation) {
...@@ -474,7 +416,7 @@ class Doctrine_Import_Schema ...@@ -474,7 +416,7 @@ class Doctrine_Import_Schema
} }
} }
if (!isset($this->_relations[$relation['class']][$newRelation['alias']])) { if ( ! isset($this->_relations[$relation['class']][$newRelation['alias']])) {
$newRelation['key'] = $this->_buildUniqueRelationKey($newRelation); $newRelation['key'] = $this->_buildUniqueRelationKey($newRelation);
$this->_relations[$relation['class']][$newRelation['alias']] = $newRelation; $this->_relations[$relation['class']][$newRelation['alias']] = $newRelation;
} }
...@@ -482,6 +424,28 @@ class Doctrine_Import_Schema ...@@ -482,6 +424,28 @@ class Doctrine_Import_Schema
} }
} }
protected function _fixDuplicateRelations()
{
foreach($this->_relations as $className => $relations) {
// This is for checking for duplicates between alias-relations and a auto-generated relations to ensure the result set of unique relations
$existingRelations = array();
$uniqueRelations = array();
foreach ($relations as $relation) {
if ( ! in_array($relation['key'], $existingRelations)) {
$existingRelations[] = $relation['key'];
$uniqueRelations = array_merge($uniqueRelations, array($relation['alias'] => $relation));
} else {
// check to see if this relationship is not autogenerated, if it's not, then the user must have explicitly declared it
if (!isset($relation['autogenerated']) || $relation['autogenerated'] != true) {
$uniqueRelations = array_merge($uniqueRelations, array($relation['alias'] => $relation));
}
}
}
$this->_relations[$className] = $uniqueRelations;
}
}
/** /**
* _buildUniqueRelationKey * _buildUniqueRelationKey
* *
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -75,10 +75,8 @@ class Doctrine_Import_Schema_TestCase extends Doctrine_UnitTestCase ...@@ -75,10 +75,8 @@ class Doctrine_Import_Schema_TestCase extends Doctrine_UnitTestCase
$this->schema = $this->buildSchema->buildSchema('schema.yml', 'yml'); $this->schema = $this->buildSchema->buildSchema('schema.yml', 'yml');
foreach ($this->schema as $name => $properties) { foreach ($this->schema as $name => $properties) {
$relations = $this->buildSchema->getRelations($properties); foreach ($properties['relations'] as $alias => $relation) {
if ( ! $this->_verifyMultiDirectionalRelationship($name, $alias, $relation)) {
foreach ($relations as $alias => $relation) {
if (!$this->_verifyMultiDirectionalRelationship($name, $alias, $relation)) {
$this->fail(); $this->fail();
return false; return false;
...@@ -94,7 +92,7 @@ class Doctrine_Import_Schema_TestCase extends Doctrine_UnitTestCase ...@@ -94,7 +92,7 @@ class Doctrine_Import_Schema_TestCase extends Doctrine_UnitTestCase
$foreignClass = $relation['class']; $foreignClass = $relation['class'];
$foreignAlias = isset($relation['foreignAlias']) ? $relation['foreignAlias']:$class; $foreignAlias = isset($relation['foreignAlias']) ? $relation['foreignAlias']:$class;
$foreignClassRelations = $this->buildSchema->getRelations($this->schema[$foreignClass]); $foreignClassRelations = $this->schema[$foreignClass]['relations'];
// Check to see if the foreign class has the opposite end defined for the class/foreignAlias // Check to see if the foreign class has the opposite end defined for the class/foreignAlias
if (isset($foreignClassRelations[$foreignAlias])) { if (isset($foreignClassRelations[$foreignAlias])) {
......
...@@ -50,3 +50,5 @@ spl_autoload_register(array('Doctrine', 'autoload')); ...@@ -50,3 +50,5 @@ spl_autoload_register(array('Doctrine', 'autoload'));
$pdo = new PDO(DSN); $pdo = new PDO(DSN);
Doctrine_Manager::connection($pdo, 'sandbox'); Doctrine_Manager::connection($pdo, 'sandbox');
Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE);
\ No newline at end of file
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
chdir(dirname(__FILE__)); chdir(dirname(__FILE__));
include('cli.php'); include('doctrine.php');
\ No newline at end of file \ 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