1
0
mirror of synced 2024-12-14 23:26:04 +03:00

[2.0][DDC-449] Fixing issue with ClassMetadataReader and existing driver sources being added

This commit is contained in:
jwage 2010-03-24 15:31:54 +00:00
parent b2167985ad
commit 0b68e9473d
4 changed files with 33 additions and 16 deletions

View File

@ -26,7 +26,8 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo,
Doctrine\ORM\Mapping\MappingException, Doctrine\ORM\Mapping\MappingException,
Doctrine\ORM\Mapping\Driver\Driver, Doctrine\ORM\Mapping\Driver\Driver,
Doctrine\ORM\Mapping\Driver\AnnotationDriver, Doctrine\ORM\Mapping\Driver\AnnotationDriver,
Doctrine\ORM\EntityManager; Doctrine\ORM\EntityManager,
Doctrine\ORM\Tools\Export\ExportException;
/** /**
* Class to read metadata mapping information from multiple sources into an array * Class to read metadata mapping information from multiple sources into an array
@ -92,9 +93,15 @@ class ClassMetadataReader
* directories. Reads the mapping directories and populates ClassMetadataInfo * directories. Reads the mapping directories and populates ClassMetadataInfo
* instances. * instances.
* *
* If you specify $autoload = true then this method will return ClassMetadata
* instances instead of ClassMetadataInfo instances. Keep in mind that if you
* specify it to autoload and it doesn't find the class your autoloader may
* throw an error.
*
* @param bool $autoload Whether or to try and autoload the classes
* @return array $classes * @return array $classes
*/ */
public function getMetadatas() public function getMetadatas($autoload = false)
{ {
$classes = array(); $classes = array();
@ -104,7 +111,7 @@ class ClassMetadataReader
$allClasses = $driver->getAllClassNames(); $allClasses = $driver->getAllClassNames();
foreach ($allClasses as $className) { foreach ($allClasses as $className) {
if (class_exists($className, false)) { if (class_exists($className, $autoload)) {
$metadata = new ClassMetadata($className); $metadata = new ClassMetadata($className);
} else { } else {
$metadata = new ClassMetadataInfo($className); $metadata = new ClassMetadataInfo($className);
@ -183,9 +190,12 @@ class ClassMetadataReader
private function _determineSourceType($source) private function _determineSourceType($source)
{ {
if ($source instanceof \Doctrine\ORM\Mapping\Driver\Driver) {
$type = array_search(get_class($source), self::$_mappingDrivers);
return $type;
// If the --from=<VALUE> is a directory lets determine if it is // If the --from=<VALUE> is a directory lets determine if it is
// annotations, yaml, xml, etc. // annotations, yaml, xml, etc.
if (is_dir($source)) { } else if (is_dir($source)) {
$source = realpath($source); $source = realpath($source);
// Find the files in the directory // Find the files in the directory
@ -218,12 +228,14 @@ class ClassMetadataReader
private function _getSourceByType($type, $source) private function _getSourceByType($type, $source)
{ {
$source = realpath($source);
// If --from==database then the source is an instance of SchemaManager // If --from==database then the source is an instance of SchemaManager
// for the current EntityMAnager // for the current EntityManager
if ($type == 'database' && $this->_em) { if ($type == 'database') {
return $this->_em->getConnection()->getSchemaManager(); if ($source instanceof \Doctrine\ORM\Mapping\Driver\DatabaseDriver) {
return $source;
} else if ($this->_em) {
return $this->_em->getConnection()->getSchemaManager();
}
// If source is annotation then lets try and find the existing annotation // If source is annotation then lets try and find the existing annotation
// driver for the source instead of re-creating a new instance // driver for the source instead of re-creating a new instance
} else if ($type == 'annotation') { } else if ($type == 'annotation') {

View File

@ -23,6 +23,7 @@
namespace Doctrine\ORM\Tools\Export; namespace Doctrine\ORM\Tools\Export;
use Doctrine\ORM\Tools\ClassMetadataReader, use Doctrine\ORM\Tools\ClassMetadataReader,
Doctrine\ORM\Tools\Export\ExportException,
Doctrine\ORM\EntityManager; Doctrine\ORM\EntityManager;
/** /**

View File

@ -2,12 +2,17 @@
namespace Doctrine\ORM\Tools\Export; namespace Doctrine\ORM\Tools\Export;
class ExportException extends ORMException { use Doctrine\ORM\ORMException;
public static function invalidExporterDriverType($type) {
class ExportException extends ORMException
{
public static function invalidExporterDriverType($type)
{
return new self("The specified export driver '$type' does not exist"); return new self("The specified export driver '$type' does not exist");
} }
public static function invalidMappingDriverType($type) { public static function invalidMappingDriverType($type)
{
return new self("The mapping driver '$type' does not exist"); return new self("The mapping driver '$type' does not exist");
} }
} }

View File

@ -4,7 +4,7 @@ namespace Doctrine\Tests\ORM\Functional;
require_once __DIR__ . '/../../TestInit.php'; require_once __DIR__ . '/../../TestInit.php';
use Doctrine\ORM\Tools\Export\ClassMetadataExporter; use Doctrine\ORM\Tools\ClassMetadataReader;
class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
{ {
@ -88,9 +88,8 @@ class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
*/ */
protected function extractClassMetadata($className) protected function extractClassMetadata($className)
{ {
$cm = new ClassMetadataExporter(); $cm = new ClassMetadataReader();
$cm->addMappingSource($this->_sm); $cm->addMappingSource(new \Doctrine\ORM\Mapping\Driver\DatabaseDriver($this->_sm));
$exporter = $cm->getExporter('yaml');
$metadatas = $cm->getMetadatas(); $metadatas = $cm->getMetadatas();
$output = false; $output = false;