diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 99df4ccfd..d7de28c05 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -191,6 +191,20 @@ class ClassMetadataFactory $this->_loadedMetadata[$className] = $class; } + protected function _getParentClasses($name) + { + // Collect parent classes, ignoring transient (not-mapped) classes. + //TODO: Evaluate whether we can use class_parents() here. + $parentClass = $name; + $parentClasses = array(); + while ($parentClass = get_parent_class($parentClass)) { + if ( ! $this->_driver->isTransient($parentClass)) { + $parentClasses[] = $parentClass; + } + } + return array_reverse($parentClasses); + } + /** * Loads the metadata of the class in question and all it's ancestors whose metadata * is still not loaded. @@ -205,17 +219,8 @@ class ClassMetadataFactory } $loaded = array(); - - // Collect parent classes, ignoring transient (not-mapped) classes. - //TODO: Evaluate whether we can use class_parents() here. - $parentClass = $name; - $parentClasses = array(); - while ($parentClass = get_parent_class($parentClass)) { - if ( ! $this->_driver->isTransient($parentClass)) { - $parentClasses[] = $parentClass; - } - } - $parentClasses = array_reverse($parentClasses); + + $parentClasses = $this->_getParentClasses($name); $parentClasses[] = $name; // Move down the hierarchy of parent classes, starting from the topmost class @@ -354,7 +359,7 @@ class ClassMetadataFactory * * @param Doctrine\ORM\Mapping\ClassMetadata $class */ - private function _completeIdGeneratorMapping(ClassMetadata $class) + private function _completeIdGeneratorMapping(ClassMetadataInfo $class) { $idGenType = $class->generatorType; if ($idGenType == ClassMetadata::GENERATOR_TYPE_AUTO) { diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php index 119a08c1b..ccb29cf14 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php @@ -25,7 +25,8 @@ use Symfony\Components\Console\Input\InputArgument, Symfony\Components\Console\Input\InputOption, Symfony\Components\Console, Doctrine\ORM\Tools\Console\MetadataFilter, - Doctrine\ORM\Tools\EntityGenerator; + Doctrine\ORM\Tools\EntityGenerator, + Doctrine\ORM\Tools\DisconnectedClassMetadataFactory; /** * Command to generate entity classes and method stubs from your mapping information. @@ -95,7 +96,8 @@ EOT { $em = $this->getHelper('em')->getEntityManager(); - $metadatas = $em->getMetadataFactory()->getAllMetadata(); + $cmf = new DisconnectedClassMetadataFactory($em); + $metadatas = $cmf->getAllMetadata(); $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter')); // Process destination directory diff --git a/lib/Doctrine/ORM/Tools/DisconnectedClassMetadataFactory.php b/lib/Doctrine/ORM/Tools/DisconnectedClassMetadataFactory.php new file mode 100644 index 000000000..1bfb6de3a --- /dev/null +++ b/lib/Doctrine/ORM/Tools/DisconnectedClassMetadataFactory.php @@ -0,0 +1,59 @@ +. + */ + +namespace Doctrine\ORM\Tools; + +use Doctrine\ORM\Mapping\ClassMetadataFactory; +use Doctrine\ORM\Mapping\ClassMetadataInfo; + +/** + * The ClassMetadataFactory is used to create ClassMetadataInfo objects + * that do not require the entity class actually exist. This allows us to + * load some mapping information and use it to do things like generate code + * from the mapping information. + * + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.org + * @since 2.0 + * @version $Revision$ + * @author Benjamin Eberlei + * @author Guilherme Blanco + * @author Jonathan Wage + * @author Roman Borschel + */ +class DisconnectedClassMetadataFactory extends ClassMetadataFactory +{ + /** + * @override + */ + protected function _newClassMetadataInstance($className) + { + return new ClassMetadataInfo($className); + } + + /** + * @override + */ + protected function _getParentClasses($name) + { + return array(); + } +} \ No newline at end of file