1
0
mirror of synced 2025-01-18 22:41:43 +03:00

DDC-897 - Make ClassMetadataFactory configurable.

This commit is contained in:
Benjamin Eberlei 2010-11-27 20:53:26 +01:00
parent 7196999b69
commit dff5dae416
10 changed files with 44 additions and 13 deletions

View File

@ -462,4 +462,25 @@ class Configuration extends \Doctrine\DBAL\Configuration
{
$this->_attributes['customHydrationModes'][$modeName] = $hydrator;
}
/**
* Set a class metadata factory.
*
* @param string $cmf
*/
public function setClassMetadataFactoryName($cmfName)
{
$this->_attributes['classMetadataFactoryName'] = $cmfName;
}
/**
* @return string
*/
public function getClassMetadataFactoryName()
{
if (!isset($this->_attributes['classMetadataFactoryName'])) {
$this->_attributes['classMetadataFactoryName'] = 'Doctrine\ORM\Mapping\ClassMetadataFactory';
}
return $this->_attributes['classMetadataFactoryName'];
}
}

View File

@ -118,8 +118,12 @@ class EntityManager
$this->conn = $conn;
$this->config = $config;
$this->eventManager = $eventManager;
$this->metadataFactory = new ClassMetadataFactory($this);
$metadataFactoryClassName = $config->getClassMetadataFactoryName();
$this->metadataFactory = new $metadataFactoryClassName;
$this->metadataFactory->setEntityManager($this);
$this->metadataFactory->setCacheDriver($this->config->getMetadataCacheImpl());
$this->unitOfWork = new UnitOfWork($this);
$this->proxyFactory = new ProxyFactory($this,
$config->getProxyDir(),

View File

@ -74,11 +74,9 @@ class ClassMetadataFactory
private $initialized = false;
/**
* Creates a new factory instance that uses the given metadata driver implementation.
*
* @param $driver The metadata driver to use.
* @param EntityManager $$em
*/
public function __construct(EntityManager $em)
public function setEntityManager(EntityManager $em)
{
$this->em = $em;
}

View File

@ -96,7 +96,8 @@ EOT
{
$em = $this->getHelper('em')->getEntityManager();
$cmf = new DisconnectedClassMetadataFactory($em);
$cmf = new DisconnectedClassMetadataFactory();
$cmf->setEntityManager($em);
$metadatas = $cmf->getAllMetadata();
$metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));

View File

@ -122,7 +122,8 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
$em = $this->_getTestEntityManager();
$em->getConfiguration()->setMetadataDriverImpl($annotationDriver);
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory($em);
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
$factory->setEntityManager($em);
$classPage = new ClassMetadata('Doctrine\Tests\Models\DirectoryTree\File');
$classPage = $factory->getMetadataFor('Doctrine\Tests\Models\DirectoryTree\File');

View File

@ -11,7 +11,8 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase
private $_factory;
protected function setUp() {
$this->_factory = new ClassMetadataFactory($this->_getTestEntityManager());
$this->_factory = new ClassMetadataFactory();
$this->_factory->setEntityManager($this->_getTestEntityManager());
}
/**

View File

@ -42,7 +42,8 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
$cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO);
// SUT
$cmf = new ClassMetadataFactoryTestSubject($entityManager);
$cmf = new ClassMetadataFactoryTestSubject();
$cmf->setEntityManager($entityManager);
$cmf->setMetadataForClass('Doctrine\Tests\ORM\Mapping\TestEntity1', $cm1);
// Prechecks

View File

@ -31,7 +31,8 @@ class YamlMappingDriverTest extends AbstractMappingDriverTest
$em = $this->_getTestEntityManager();
$em->getConfiguration()->setMetadataDriverImpl($yamlDriver);
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory($em);
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
$factory->setEntityManager($em);
$classPage = new ClassMetadata('Doctrine\Tests\Models\DirectoryTree\File');
$classPage = $factory->getMetadataFor('Doctrine\Tests\Models\DirectoryTree\File');

View File

@ -77,7 +77,8 @@ class ConvertDoctrine1SchemaTest extends \Doctrine\Tests\OrmTestCase
$metadataDriver = new \Doctrine\ORM\Mapping\Driver\YamlDriver(__DIR__ . '/convert');
$em = $this->_createEntityManager($metadataDriver);
$cmf = new DisconnectedClassMetadataFactory($em);
$cmf = new DisconnectedClassMetadataFactory();
$cmf->setEntityManager($em);
$metadata = $cmf->getAllMetadata();
$profileClass = $metadata[0];
$userClass = $metadata[1];

View File

@ -88,10 +88,12 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest
protected function _createClassMetadataFactory($em, $type)
{
if ($type === 'annotation') {
return new ClassMetadataFactory($em);
$factory = new ClassMetadataFactory();
} else {
return new DisconnectedClassMetadataFactory($em);
$factory = new DisconnectedClassMetadataFactory();
}
$factory->setEntityManager($em);
return $factory;
}
public function testExportDirectoryAndFilesAreCreated()