コード例 #1
0
 /**
  * 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);
 }
コード例 #2
0
 /**
  * Create a new MongoClient connection.
  *
  * @param string $dsn
  * @param array  $config
  * @param array  $options
  *
  * @return MongoClient
  */
 protected function createConnection()
 {
     $databaseName = $this->config['database'];
     $documentPaths = array($this->config['models_dir']);
     $httpClient = new \Doctrine\CouchDB\HTTP\SocketClient($this->config['host'], $this->config['port'], $this->config['username'], $this->config['password'], $this->config['ip'], $this->config['ssl']);
     $httpClient->setOption('keep-alive', $this->config['keep-alive']);
     //$httpClient->setOption('timeout', $this->config['timeout']);
     $this->configManager = new \Doctrine\ODM\CouchDB\Configuration();
     //$this->metadataDriver = $this->configManager->newDefaultAnnotationDriver($documentPaths);
     $this->metadataDriver = new AnnotationDriver(new AnnotationReader(), $documentPaths);
     // registering noop annotation autoloader - allow all annotations by default
     AnnotationRegistry::registerLoader('class_exists');
     $this->configManager->setProxyDir($this->config['proxies_dir']);
     $this->configManager->setMetadataDriverImpl($this->metadataDriver);
     $this->configManager->setLuceneHandlerName($this->config['lucene_handler_name']);
     $connection = new \Doctrine\CouchDB\CouchDBClient($httpClient, $databaseName);
     $this->dm = new \Doctrine\ODM\CouchDB\DocumentManager($connection, $this->configManager);
     $view = new FolderDesignDocument($this->config['views_folder']);
     $connection->createDesignDocument('couchdb', $view);
     return $connection;
 }