/**
  * Creates a Doctrine ODM DocumentManager
  *
  * @return \Doctrine\ODM\CouchDB\DocumentManager
  */
 public function create()
 {
     if (isset($this->documentManager)) {
         return $this->documentManager;
     }
     $httpClient = new \Doctrine\CouchDB\HTTP\SocketClient($this->settings['host'], $this->settings['port'], $this->settings['username'], $this->settings['password'], $this->settings['ip']);
     $reader = new \Doctrine\Common\Annotations\AnnotationReader();
     $metaDriver = new \Doctrine\ODM\CouchDB\Mapping\Driver\AnnotationDriver($reader);
     $config = new \Doctrine\ODM\CouchDB\Configuration();
     $config->setMetadataDriverImpl($metaDriver);
     $packages = $this->packageManager->getActivePackages();
     foreach ($packages as $package) {
         $designDocumentRootPath = \TYPO3\Flow\Utility\Files::concatenatePaths(array($package->getPackagePath(), 'Migrations/CouchDB/DesignDocuments'));
         if (is_dir($designDocumentRootPath)) {
             $packageDesignDocumentFolders = glob($designDocumentRootPath . '/*');
             foreach ($packageDesignDocumentFolders as $packageDesignDocumentFolder) {
                 if (is_dir($packageDesignDocumentFolder)) {
                     $designDocumentName = strtolower(basename($packageDesignDocumentFolder));
                     $config->addDesignDocument($designDocumentName, 'Radmiraal\\CouchDB\\View\\Migration', array('packageKey' => $package->getPackageKey(), 'path' => $packageDesignDocumentFolder));
                 }
             }
         }
     }
     $proxyDirectory = \TYPO3\Flow\Utility\Files::concatenatePaths(array($this->environment->getPathToTemporaryDirectory(), 'DoctrineODM/Proxies'));
     \TYPO3\Flow\Utility\Files::createDirectoryRecursively($proxyDirectory);
     $config->setProxyDir($proxyDirectory);
     $config->setProxyNamespace('TYPO3\\Flow\\Persistence\\DoctrineODM\\Proxies');
     $config->setAutoGenerateProxyClasses(TRUE);
     $couchClient = new \Doctrine\CouchDB\CouchDBClient($httpClient, $this->settings['databaseName']);
     $this->documentManager = \Doctrine\ODM\CouchDB\DocumentManager::create($couchClient, $config);
     return $this->documentManager;
 }
 /**
  * Create a couchdb connection.
  *
  * @param array $connectionData Connection information
  *
  * @return [type] [description]
  */
 public function createConnection($connectionData)
 {
     //now we change the default values for the ones the user configured
     $default_config = ['database' => '', 'host' => 'localhost', 'port' => 5984, 'username' => null, 'password' => null, 'ip' => null, 'ssl' => false, 'models_dir' => app_path(), 'lucene_handler_name' => '_fti', 'proxies_dir' => app_path() . 'storage' . DIRECTORY_SEPARATOR . 'proxies', 'keep-alive' => true, 'timeout' => '0.01', 'views_folder' => '../app/couchdb', 'viewsname' => 'couchsource'];
     $config = array_replace_recursive($default_config, $connectionData);
     $databaseName = $config['database'];
     $documentPaths = array($config['models_dir']);
     $httpClient = new \Doctrine\CouchDB\HTTP\SocketClient($config['host'], $config['port'], $config['username'], $config['password'], $config['ip'], $config['ssl']);
     $httpClient->setOption('keep-alive', $config['keep-alive']);
     $configManager = new \Doctrine\ODM\CouchDB\Configuration();
     $this->metadataDriver = new AnnotationDriver(new AnnotationReader(), $documentPaths);
     // registering noop annotation autoloader - allow all annotations by default
     AnnotationRegistry::registerLoader('class_exists');
     $configManager->setProxyDir($config['proxies_dir']);
     $configManager->setMetadataDriverImpl($this->metadataDriver);
     $configManager->setLuceneHandlerName($config['lucene_handler_name']);
     $connection = new \Doctrine\CouchDB\CouchDBClient($httpClient, $databaseName);
     $view = new FolderDesignDocument($config['views_folder']);
     $connection->createDesignDocument($config['viewsname'], $view);
     $this->dm = new \Doctrine\ODM\CouchDB\DocumentManager($connection, $configManager);
 }