public function testHasGetMetadata_NamespaceSeperatorIsNotNormalized() { require_once __DIR__ . "/../../Models/Global/GlobalNamespaceModel.php"; $reader = new \Doctrine\Common\Annotations\AnnotationReader(new \Doctrine\Common\Cache\ArrayCache()); $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\'); $metadataDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader); $metadataDriver->addPaths(array(__DIR__ . '/../../Models/Global/')); $entityManager = $this->_createEntityManager($metadataDriver); $mf = $entityManager->getMetadataFactory(); $m1 = $mf->getMetadataFor("DoctrineGlobal_Article"); $h1 = $mf->hasMetadataFor("DoctrineGlobal_Article"); $h2 = $mf->hasMetadataFor("\\DoctrineGlobal_Article"); $m2 = $mf->getMetadataFor("\\DoctrineGlobal_Article"); $this->assertNotSame($m1, $m2); $this->assertFalse($h2); $this->assertTrue($h1); }
/** * Setup the metadata driver if necessary options are set. Otherwise Doctrine defaults are used (AnnotationReader). * * @param array $options * @param Doctrine\ORM\Configuration $config * @param Doctrine\Common\Cache\AbstractCache $cache * @param Doctrine\DBAL\Connection $conn */ protected function _setupMetadataDriver($options, $config, $cache, $conn) { $driver = false; if (isset($options['metadata'])) { if (isset($options['metadata']['driver'])) { $driverName = $options['metadata']['driver']; switch (strtolower($driverName)) { case 'annotation': $driverName = 'Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver'; break; case 'yaml': $driverName = 'Doctrine\\ORM\\Mapping\\Driver\\YamlDriver'; break; case 'xml': $driverName = 'Doctrine\\ORM\\Mapping\\Driver\\XmlDriver'; break; case 'php': $driverName = 'Doctrine\\ORM\\Mapping\\Driver\\PhpDriver'; break; case 'database': $driverName = 'Doctrine\\ORM\\Mapping\\Driver\\DatabaseDriver'; break; } if (!class_exists($driverName)) { throw new ZendX_Doctrine2_Exception("MetadataDriver class '" . $driverName . "' does not exist"); } if (in_array('Doctrine\\ORM\\Mapping\\Driver\\AbstractFileDriver', class_parents($driverName))) { if (!isset($options['metadata']['paths'])) { throw new ZendX_Doctrine2_Exception("Metadata Driver is file based, but no config file paths were given."); } if (!isset($options['metadata']['mode'])) { $options['metadata']['mode'] = \Doctrine\ORM\Mapping\Driver\AbstractFileDriver::FILE_PER_CLASS; } $driver = new $driverName($options['metadata']['paths'], $options['metadata']['mode']); } elseif ($driverName == 'Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver') { $reader = new \Doctrine\Common\Annotations\AnnotationReader($cache); $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\'); $driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader); if (isset($options['metadata']['classDirectory'])) { $driver->addPaths(array($options['metadata']['classDirectory'])); } else { throw new ZendX_Doctrine2_Exception("Doctrine Annotation Driver requires to set a class directory for the entities."); } //$driverImpl = $config->newDefaultAnnotationDriver("var/www/zfbench/application/models")); //$config->setMetadataDriverImpl($driverImpl); } elseif ($driverName == 'Doctrine\\ORM\\Mapping\\Driver\\DatabaseDriver') { $schemaManager = $conn->getSchemaManager(); $driver = new \Doctrine\ORM\Mapping\Driver\DatabaseDriver($schemaManager); } if (!$driver instanceof \Doctrine\ORM\Mapping\Driver\Driver) { throw new ZendX_Doctrine2_Exception("No metadata driver could be loaded."); } $config->setMetadataDriverImpl($driver); } } }