Bisna\Doctrine\Container::startODMMetadata PHP Method

startODMMetadata() private method

Initialize ODM Metadata drivers.
private startODMMetadata ( array $config = [] ) : Doctrine\ODM\MongoDB\Mapping\Driver\DriverChain
$config array ODM Mapping drivers.
return Doctrine\ODM\MongoDB\Mapping\Driver\DriverChain
    private function startODMMetadata(array $config = array())
    {
        $metadataDriver = new \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain();
        // Default metadata driver configuration
        $defaultMetadataDriver = array('adapterClass' => 'Doctrine\\ODM\\MongoDB\\Mapping\\Driver\\AnnotationDriver', 'mappingNamespace' => '', 'mappingDirs' => array(), 'annotationReaderClass' => 'Doctrine\\Common\\Annotations\\AnnotationReader', 'annotationReaderCache' => $this->defaultCacheInstance, 'annotationReaderNamespaces' => array());
        // Setup ODM AnnotationRegistry
        if (isset($config['annotationRegistry'])) {
            $this->startAnnotationRegistry($config['annotationRegistry']);
        }
        foreach ($config['drivers'] as $driver) {
            $driver = array_replace_recursive($defaultMetadataDriver, $driver);
            if (method_exists($driver['adapterClass'], 'registerAnnotationClasses')) {
                $driver['adapterClass']::registerAnnotationClasses();
            }
            $reflClass = new \ReflectionClass($driver['adapterClass']);
            $nestedDriver = null;
            if ($reflClass->getName() == 'Doctrine\\ODM\\MongoDB\\Mapping\\Driver\\AnnotationDriver' || $reflClass->isSubclassOf('Doctrine\\ODM\\MongoDB\\Mapping\\Driver\\AnnotationDriver')) {
                $annotationReaderClass = $driver['annotationReaderClass'];
                $annotationReader = new $annotationReaderClass();
                if (method_exists($annotationReader, 'setDefaultAnnotationNamespace')) {
                    $annotationReader->setDefaultAnnotationNamespace('Doctrine\\ODM\\MongoDB\\Mapping\\');
                }
                if (method_exists($annotationReader, 'setAnnotationNamespaceAlias')) {
                    $driver['annotationReaderNamespaces']['ODM'] = 'Doctrine\\ODM\\MongoDB\\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;
    }