/**
  *
  * @param  \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
  * @return object
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $manifest = $serviceLocator->get('manifest');
     $extension = $serviceLocator->get('extension.odmcore');
     $config = new Configuration();
     $config->setProxyDir($extension->getProxyDir());
     $config->setProxyNamespace('Proxies');
     $config->setHydratorDir($extension->getHydratorDir());
     $config->setHydratorNamespace('Hydrators');
     $config->setDefaultDB($extension->getDefaultDb());
     $config->setClassMetadataFactoryName($extension->getClassMetadataFactory());
     $config->setMetadataCacheImpl(new ArrayCache());
     //create driver chain
     $chain = new MappingDriverChain();
     foreach ($manifest->getModels() as $namespace => $path) {
         $driver = new AnnotationDriver(new AnnotationReader(), $path);
         $chain->addDriver($driver, $namespace);
     }
     $config->setMetadataDriverImpl($chain);
     //register filters
     foreach ($extension->getFilters() as $name => $class) {
         $config->addFilter($name, $class);
     }
     //create event manager
     $eventManager = new EventManager();
     foreach ($manifest->getSubscribers() as $subscriber) {
         $eventManager->addEventSubscriber($serviceLocator->get($subscriber));
     }
     //register annotations
     AnnotationRegistry::registerLoader(function ($className) {
         return class_exists($className);
     });
     $conn = new Connection(null, array(), $config);
     return ModelManager::create($conn, $config, $eventManager);
 }
 /**
  * @param  \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
  * @return \Doctrine\ODM\MongoDB\DocumentManager
  */
 public function build($options)
 {
     if (is_array($options) || $options instanceof \Traversable) {
         $options = new DocumentManagerOptions($options);
     } elseif (!$options instanceof DocumentManagerOptions) {
         throw new Exception\InvalidArgumentException();
     }
     return ModelManager::create($this->serviceLocator->get($options->getConnection()), $this->serviceLocator->get($options->getConfiguration()), $this->serviceLocator->get($options->getEventManager()));
 }