private function startORMMetadata(array $config = array())
{
$metadataDriver = new \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain();
// Default metadata driver configuration
$defaultMetadataDriver = array('adapterClass' => 'Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver', 'mappingNamespace' => '', 'mappingDirs' => array(), 'annotationReaderClass' => 'Doctrine\\Common\\Annotations\\AnnotationReader', 'annotationReaderCache' => $this->defaultCacheInstance, 'annotationReaderNamespaces' => array());
// Setup AnnotationRegistry
if (isset($config['annotationRegistry'])) {
$this->startAnnotationRegistry($config['annotationRegistry']);
}
foreach ($config['drivers'] as $driver) {
$driver = array_replace_recursive($defaultMetadataDriver, $driver);
$reflClass = new \ReflectionClass($driver['adapterClass']);
$nestedDriver = null;
if ($reflClass->getName() == 'Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver' || $reflClass->isSubclassOf('Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver')) {
$annotationReaderClass = $driver['annotationReaderClass'];
$annotationReader = new $annotationReaderClass();
// For Doctrine >= 2.2
if (method_exists($annotationReader, 'addNamespace')) {
$annotationReader->addNamespace('Doctrine\\ORM\\Mapping');
}
if (method_exists($annotationReader, 'setDefaultAnnotationNamespace')) {
$annotationReader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
}
if (method_exists($annotationReader, 'setAnnotationNamespaceAlias')) {
$driver['annotationReaderNamespaces']['ORM'] = 'Doctrine\\ORM\\Mapping\\';
foreach ($driver['annotationReaderNamespaces'] as $alias => $namespace) {
$annotationReader->setAnnotationNamespaceAlias($namespace, $alias);
}
}
$indexedReader = new \Doctrine\Common\Annotations\CachedReader(new \Doctrine\Common\Annotations\IndexedReader($annotationReader), $this->getCacheInstance($driver['annotationReaderCache']));
$nestedDriver = $reflClass->newInstance($indexedReader, $driver['mappingDirs']);
} else {
$nestedDriver = $reflClass->newInstance($driver['mappingDirs']);
}
$metadataDriver->addDriver($nestedDriver, $driver['mappingNamespace']);
}
if (($drivers = $metadataDriver->getDrivers()) && count($drivers) == 1) {
reset($drivers);
$metadataDriver = $drivers[key($drivers)];
}
return $metadataDriver;
}