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'];
} }
} }
......
This diff is collapsed.
This diff is collapsed.
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