Fixes to loading models and made it so Builder can generate abstract classes.
This commit is contained in:
parent
e7e153d948
commit
a085706070
@ -483,24 +483,14 @@ final class Doctrine
|
|||||||
// and currently declared classes
|
// and currently declared classes
|
||||||
foreach ($classes as $name) {
|
foreach ($classes as $name) {
|
||||||
$class = new ReflectionClass($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();
|
// Skip the following classes
|
||||||
if ($class === false) {
|
// - abstract classes
|
||||||
break;
|
// - not a subclass of Doctrine_Record
|
||||||
}
|
// - don't have a setTableDefinition method
|
||||||
}
|
if ($class->isAbstract() ||
|
||||||
|
!$class->isSubClassOf($parent) ||
|
||||||
if ($class === false) {
|
!$class->hasMethod('setTableDefinition')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ class Doctrine_Import_Builder
|
|||||||
/**
|
/**
|
||||||
* This class has been auto-generated by the Doctrine ORM Framework
|
* This class has been auto-generated by the Doctrine ORM Framework
|
||||||
*/
|
*/
|
||||||
class %s extends %s
|
%sclass %s extends %s
|
||||||
{
|
{
|
||||||
%s
|
%s
|
||||||
%s
|
%s
|
||||||
@ -273,18 +273,14 @@ END;
|
|||||||
throw new Doctrine_Import_Builder_Exception('Missing class name.');
|
throw new Doctrine_Import_Builder_Exception('Missing class name.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$abstract = isset($options['abstract']) ? 'abstract ':null;
|
||||||
$className = $options['className'];
|
$className = $options['className'];
|
||||||
$extends = isset($options['inheritance']['extends']) ? $options['inheritance']['extends']:'Doctrine_Record';
|
$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'])) {
|
$content = sprintf(self::$tpl, $abstract,
|
||||||
$definition = $this->buildTableDefinition($options, $columns, $relations);
|
$className,
|
||||||
$setUp = $this->buildSetUp($options, $columns, $relations);
|
|
||||||
} else {
|
|
||||||
$definition = null;
|
|
||||||
$setUp = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$content = sprintf(self::$tpl, $className,
|
|
||||||
$extends,
|
$extends,
|
||||||
$definition,
|
$definition,
|
||||||
$setUp);
|
$setUp);
|
||||||
@ -313,7 +309,8 @@ END;
|
|||||||
|
|
||||||
if ($this->generateBaseClasses()) {
|
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;
|
$optionsBak = $options;
|
||||||
|
|
||||||
unset($options['tableName']);
|
unset($options['tableName']);
|
||||||
@ -321,7 +318,7 @@ END;
|
|||||||
$this->writeDefinition($options, array(), array());
|
$this->writeDefinition($options, array(), array());
|
||||||
|
|
||||||
$options = $optionsBak;
|
$options = $optionsBak;
|
||||||
//}
|
}
|
||||||
|
|
||||||
$generatedPath = $this->path . DIRECTORY_SEPARATOR . $this->baseClassesDirectory;
|
$generatedPath = $this->path . DIRECTORY_SEPARATOR . $this->baseClassesDirectory;
|
||||||
|
|
||||||
@ -330,6 +327,7 @@ END;
|
|||||||
}
|
}
|
||||||
|
|
||||||
$options['className'] = 'Base' . $options['className'];
|
$options['className'] = 'Base' . $options['className'];
|
||||||
|
$options['abstract'] = true;
|
||||||
$options['fileName'] = $generatedPath . DIRECTORY_SEPARATOR . $options['className'] . $this->suffix;
|
$options['fileName'] = $generatedPath . DIRECTORY_SEPARATOR . $options['className'] . $this->suffix;
|
||||||
|
|
||||||
$this->writeDefinition($options, $columns, $relations);
|
$this->writeDefinition($options, $columns, $relations);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user