Fixes to loading models and made it so Builder can generate abstract classes.
This commit is contained in:
parent
e7e153d948
commit
a085706070
@ -442,7 +442,7 @@ final class Doctrine
|
||||
public static function loadModels($directory)
|
||||
{
|
||||
$declared = get_declared_classes();
|
||||
|
||||
|
||||
if ($directory !== null) {
|
||||
foreach ((array) $directory as $dir) {
|
||||
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir),
|
||||
@ -483,24 +483,14 @@ final class Doctrine
|
||||
// and currently declared classes
|
||||
foreach ($classes as $name) {
|
||||
$class = new ReflectionClass($name);
|
||||
$conn = Doctrine_Manager::getInstance()->getConnectionForComponent($name);
|
||||
// check if class is an instance of Doctrine_Record and not abstract
|
||||
// class must have method setTableDefinition (to avoid non-Record subclasses like symfony's sfDoctrineRecord)
|
||||
// we have to recursively iterate through the class parents just to be sure that the classes using for example
|
||||
// column aggregation inheritance are properly exported to database
|
||||
while ($class->isAbstract() ||
|
||||
! $class->isSubclassOf($parent) ||
|
||||
! $class->hasMethod('setTableDefinition') ||
|
||||
( $class->hasMethod('setTableDefinition') &&
|
||||
$class->getMethod('setTableDefinition')->getDeclaringClass()->getName() !== $class->getName())) {
|
||||
|
||||
$class = $class->getParentClass();
|
||||
if ($class === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($class === false) {
|
||||
// Skip the following classes
|
||||
// - abstract classes
|
||||
// - not a subclass of Doctrine_Record
|
||||
// - don't have a setTableDefinition method
|
||||
if ($class->isAbstract() ||
|
||||
!$class->isSubClassOf($parent) ||
|
||||
!$class->hasMethod('setTableDefinition')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ class Doctrine_Import_Builder
|
||||
/**
|
||||
* This class has been auto-generated by the Doctrine ORM Framework
|
||||
*/
|
||||
class %s extends %s
|
||||
%sclass %s extends %s
|
||||
{
|
||||
%s
|
||||
%s
|
||||
@ -273,18 +273,14 @@ END;
|
||||
throw new Doctrine_Import_Builder_Exception('Missing class name.');
|
||||
}
|
||||
|
||||
$abstract = isset($options['abstract']) ? 'abstract ':null;
|
||||
$className = $options['className'];
|
||||
$extends = isset($options['inheritance']['extends']) ? $options['inheritance']['extends']:'Doctrine_Record';
|
||||
$definition = !isset($options['no_definition']) ? $this->buildTableDefinition($options, $columns, $relations):null;
|
||||
$setUp = !isset($options['no_definition']) ? $this->buildSetUp($options, $columns, $relations):null;
|
||||
|
||||
if (!isset($options['no_definition'])) {
|
||||
$definition = $this->buildTableDefinition($options, $columns, $relations);
|
||||
$setUp = $this->buildSetUp($options, $columns, $relations);
|
||||
} else {
|
||||
$definition = null;
|
||||
$setUp = null;
|
||||
}
|
||||
|
||||
$content = sprintf(self::$tpl, $className,
|
||||
$content = sprintf(self::$tpl, $abstract,
|
||||
$className,
|
||||
$extends,
|
||||
$definition,
|
||||
$setUp);
|
||||
@ -313,7 +309,8 @@ END;
|
||||
|
||||
if ($this->generateBaseClasses()) {
|
||||
|
||||
//if (!file_exists($options['fileName'])) {
|
||||
// We only want to generate this one if it doesn't already exist
|
||||
if (!file_exists($options['fileName'])) {
|
||||
$optionsBak = $options;
|
||||
|
||||
unset($options['tableName']);
|
||||
@ -321,7 +318,7 @@ END;
|
||||
$this->writeDefinition($options, array(), array());
|
||||
|
||||
$options = $optionsBak;
|
||||
//}
|
||||
}
|
||||
|
||||
$generatedPath = $this->path . DIRECTORY_SEPARATOR . $this->baseClassesDirectory;
|
||||
|
||||
@ -330,6 +327,7 @@ END;
|
||||
}
|
||||
|
||||
$options['className'] = 'Base' . $options['className'];
|
||||
$options['abstract'] = true;
|
||||
$options['fileName'] = $generatedPath . DIRECTORY_SEPARATOR . $options['className'] . $this->suffix;
|
||||
|
||||
$this->writeDefinition($options, $columns, $relations);
|
||||
|
Loading…
x
Reference in New Issue
Block a user