public function loadDoctrineMongoDBConfiguration(Application $app)
 {
     $app['doctrine.odm.mongodb.configuration'] = $app->share(function () use($app) {
         $config = new Configuration();
         if ($app['doctrine.odm.mongodb.metadata_cache'] == 'apc') {
             $cache = new ApcCache();
         } else {
             $cache = new ArrayCache();
         }
         $config->setMetadataCacheImpl($cache);
         if (isset($app['doctrine.odm.mongodb.connection_options']['database'])) {
             $config->setDefaultDB($app['doctrine.odm.mongodb.connection_options']['database']);
         }
         $chain = new DriverChain();
         foreach ((array) $app['doctrine.odm.mongodb.documents'] as $document) {
             switch ($document['type']) {
                 case 'annotation':
                     $reader = new AnnotationReader();
                     $driver = new AnnotationDriver($reader, (array) $document['path']);
                     $chain->addDriver($driver, $document['namespace']);
                     break;
                 case 'yml':
                     $driver = new YamlDriver((array) $document['path']);
                     $driver->setFileExtension('.yml');
                     $chain->addDriver($driver, $document['namespace']);
                     break;
                 case 'xml':
                     $driver = new XmlDriver((array) $document['path'], $document['namespace']);
                     $driver->setFileExtension('.xml');
                     $chain->addDriver($driver, $document['namespace']);
                     break;
                 default:
                     throw new \InvalidArgumentException(sprintf('"%s" is not a recognized driver', $document['type']));
                     break;
             }
         }
         $config->setMetadataDriverImpl($chain);
         $config->setProxyDir($app['doctrine.odm.mongodb.proxies_dir']);
         $config->setProxyNamespace($app['doctrine.odm.mongodb.proxies_namespace']);
         $config->setAutoGenerateProxyClasses($app['doctrine.odm.mongodb.auto_generate_proxies']);
         $config->setHydratorDir($app['doctrine.odm.mongodb.hydrators_dir']);
         $config->setHydratorNamespace($app['doctrine.odm.mongodb.hydrators_namespace']);
         return $config;
     });
 }