/**
  * Creates the Doctrine entity manager instance.
  *
  * @param ConfigRepository $config
  *
  * @return DocumentManager
  * @throws Exception
  */
 protected function createDocumentManager(ConfigRepository $config)
 {
     $doctrineConfig = Config::getODM($config);
     $databaseConfig = Config::getDB($config);
     $connectionConfig = Config::createConnectionConfig();
     $type = array_get($doctrineConfig, 'mapping', self::METADATA_ANNOTATIONS);
     // if no paths are set set default ones
     $paths = array_get($doctrineConfig, 'paths', [base_path('app/Entities')]);
     $debug = $config['app.debug'];
     $proxyDir = array_get($doctrineConfig, 'proxy.directory');
     $simpleAnnotations = array_get($doctrineConfig, 'simple_annotations', false);
     $metadataConfiguration = $this->createMetadataConfiguration($type, $paths, $debug, $proxyDir, null, $simpleAnnotations);
     $this->configureMetadataConfiguration($metadataConfiguration, $doctrineConfig, $databaseConfig);
     $eventManager = new EventManager();
     $this->configureEventManager($doctrineConfig, $eventManager);
     $connection = new Connection($connectionConfig['host'], [], $metadataConfiguration);
     $documentManager = DocumentManager::create($connection, $metadataConfiguration, $eventManager);
     $this->configureDocumentManager($doctrineConfig, $documentManager);
     $this->documentManager = $documentManager;
     return $documentManager;
 }