1
0
mirror of synced 2024-12-13 14:56:01 +03:00

Introducing DisconnectedClassMetadataFactory that will replace the need for ClassMetadataReader

This commit is contained in:
Jonathan H. Wage 2010-04-13 18:20:41 -04:00
parent 12c9ca971b
commit 5cfe9e1d94
3 changed files with 80 additions and 14 deletions

View File

@ -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) {

View File

@ -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

View File

@ -0,0 +1,59 @@
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
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 <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class DisconnectedClassMetadataFactory extends ClassMetadataFactory
{
/**
* @override
*/
protected function _newClassMetadataInstance($className)
{
return new ClassMetadataInfo($className);
}
/**
* @override
*/
protected function _getParentClasses($name)
{
return array();
}
}