/**
  * Setups a logger function fore the queries generated
  *
  * @return void
  */
 protected function setupLogger()
 {
     if (Configure::read('debug') > 1) {
         $self = $this;
         $this->configuration->setLoggerCallable(function (array $log) use($self) {
             $self->appendQueryLog($log);
         });
     }
 }
 /**
  *
  * @param array $config
  * @return DocumentManager
  */
 public static function createDocumentManager($config, Container $container)
 {
     $configuration = new Configuration();
     if (is_null($config['eventManager'])) {
         $evm = new EventManager();
     } else {
         $evm = $config['eventManager'];
     }
     $configuration->setProxyDir($config['proxyDir']);
     $configuration->setProxyNamespace($config['proxyNamespace']);
     $configuration->setHydratorDir($config['hydratorDir']);
     $configuration->setHydratorNamespace($config['hydratorNamespace']);
     $configuration->setAutoGenerateHydratorClasses($config['autoGenerateHydratorClasses']);
     $configuration->setAutoGenerateProxyClasses($config['autoGenerateProxyClasses']);
     if (isset($config['metaDataCache'])) {
         $metadataCache = $config['metaDataCache'];
     } else {
         $metadataCache = new $config['metaDataCacheClass']();
         $metadataCache->setNamespace($config['cachePrefix']);
     }
     $configuration->setMetadataCacheImpl($metadataCache);
     AnnotationDriver::registerAnnotationClasses();
     $reader = new AnnotationReader();
     if ($config['cacheAnnotations'] == TRUE) {
         $reader = new CachedReader($reader, $metadataCache, $config['debug']);
     }
     if ($config['indexAnnotations'] == TRUE) {
         $reader = new IndexedReader($reader);
     }
     if (class_exists(\Gedmo\DoctrineExtensions::class)) {
         \Gedmo\DoctrineExtensions::registerAnnotations();
         $configuration->addFilter('soft-deleteable', \Gedmo\SoftDeleteable\Filter\ODM\SoftDeleteableFilter::class);
         foreach ($config['listeners'] as $listenerName => $enabled) {
             if ($enabled) {
                 $listener = self::configureListener($listenerName, $reader);
                 $evm->addEventSubscriber($listener);
             }
         }
     }
     $driverImpl = new AnnotationDriver($reader, $config['documentsDir']);
     $configuration->setMetadataDriverImpl($driverImpl);
     $configuration->setDefaultDB($config['dbname']);
     $logger = new Logger($config['logger'], $config['loggerPrefix']);
     $configuration->setLoggerCallable([$logger, 'logQuery']);
     $mongo = new MongoClient($config['uri'], $config['mongoOptions']);
     $connection = new Connection($mongo);
     $dm = DocumentManager::create($connection, $configuration, $evm);
     foreach ($config['filters'] as $filter => $enabled) {
         if ($enabled) {
             $dm->getFilterCollection()->enable($filter);
         }
     }
     return $dm;
 }
 /**
  * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
  * @return \Doctrine\ODM\MongoDB\Configuration
  * @throws \Exception
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /** @var $options \DoctrineMongoODMModule\Options\Configuration */
     $options = $this->getOptions($serviceLocator, 'configuration');
     $config = new Configuration();
     // logger
     if ($options->getLogger()) {
         $logger = $serviceLocator->get($options->getLogger());
         $config->setLoggerCallable(array($logger, 'log'));
     }
     // proxies
     $config->setAutoGenerateProxyClasses($options->getGenerateProxies());
     $config->setProxyDir($options->getProxyDir());
     $config->setProxyNamespace($options->getProxyNamespace());
     // hydrators
     $config->setAutoGenerateHydratorClasses($options->getGenerateHydrators());
     $config->setHydratorDir($options->getHydratorDir());
     $config->setHydratorNamespace($options->getHydratorNamespace());
     // default db
     $config->setDefaultDB($options->getDefaultDb());
     // caching
     $config->setMetadataCacheImpl($serviceLocator->get($options->getMetadataCache()));
     // retries
     $config->setRetryConnect($options->getRetryConnect());
     $config->setRetryQuery($options->getRetryQuery());
     // Register filters
     foreach ($options->getFilters() as $alias => $class) {
         $config->addFilter($alias, $class);
     }
     // the driver
     $config->setMetadataDriverImpl($serviceLocator->get($options->getDriver()));
     // metadataFactory, if set
     if ($factoryName = $options->getClassMetadataFactoryName()) {
         $config->setClassMetadataFactoryName($factoryName);
     }
     // custom types
     foreach ($options->getTypes() as $name => $class) {
         if (Type::hasType($name)) {
             Type::overrideType($name, $class);
         } else {
             Type::addType($name, $class);
         }
     }
     return $config;
 }
 /**
  * Setup logger.
  *
  * @param \Doctrine\ODM\MongoDB\Configuration $config
  * @param array                               $options
  */
 protected static function setupLogger(Configuration &$config, array $options)
 {
     if ($options['logger_callable']) {
         $config->setLoggerCallable($options['logger_callable']);
     }
 }
 private function loadDoctrineMongoDBConfiguration(Application $app)
 {
     $app['doctrine.odm.mongodb.configuration'] = $app->share(function () use($app) {
         $config = new Configuration();
         $config->setMetadataCacheImpl($app['doctrine.odm.mongodb.metadata_cache']);
         if (isset($app['doctrine.odm.mongodb.connection_options']['database'])) {
             $config->setDefaultDB($app['doctrine.odm.mongodb.connection_options']['database']);
         }
         $chain = new MappingDriverChain();
         $usingAnnotations = false;
         foreach ((array) $app['doctrine.odm.mongodb.documents'] as $document) {
             switch ($document['type']) {
                 case 'annotation':
                     $driver = AnnotationDriver::create((array) $document['path']);
                     $chain->addDriver($driver, $document['namespace']);
                     $usingAnnotations = true;
                     break;
                 case 'yml':
                     $driver = new YamlDriver((array) $document['path'], '.yml');
                     $chain->addDriver($driver, $document['namespace']);
                     break;
                 case 'xml':
                     $driver = new XmlDriver((array) $document['path'], '.xml');
                     $chain->addDriver($driver, $document['namespace']);
                     break;
                 default:
                     throw new \InvalidArgumentException(sprintf('"%s" is not a recognized driver', $document['type']));
                     break;
             }
             // add namespace alias
             if (isset($document['alias'])) {
                 $config->addDocumentNamespace($document['alias'], $document['namespace']);
             }
         }
         if ($usingAnnotations) {
             AnnotationDriver::registerAnnotationClasses();
         }
         $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']);
         $config->setAutoGenerateHydratorClasses($app['doctrine.odm.mongodb.auto_generate_hydrators']);
         $config->setLoggerCallable($app['doctrine.odm.mongodb.logger_callable']);
         return $config;
     });
 }