Пример #1
0
 public function hydrate(Jarvis $app)
 {
     $app['doctrine.cache'] = function () {
         return new VoidCache();
     };
     $app['doctrine.annotation.driver'] = function () {
         return new AnnotationDriver(new AnnotationReader());
     };
     $app['entyMgr'] = function (Jarvis $app) : EntityManagerInterface {
         $settings = $app['doctrine.settings'];
         $cache = $app['doctrine.cache'];
         $config = Setup::createConfiguration($settings['debug'], $settings['proxies_dir'], $cache);
         $driver = $app['doctrine.annotation.driver'];
         if (isset($settings['entities_paths'])) {
             $driver->addPaths((array) $settings['entities_paths']);
         }
         AnnotationRegistry::registerLoader('class_exists');
         $config->setMetadataDriverImpl($driver);
         $config->setAutoGenerateProxyClasses($settings['debug']);
         $config->setMetadataCacheImpl($cache);
         $config->setResultCacheImpl($cache);
         $config->setQueryCacheImpl($cache);
         $entyMgr = EntityManager::create($settings['dbal'], $config);
         if (isset($app['doctrine.orm.entyMgr.decorator']) && is_string($fqcn = $app['doctrine.orm.entyMgr.decorator']) && is_subclass_of($fqcn, EntityManagerDecorator::class)) {
             $entyMgr = new $fqcn($entyMgr);
         }
         $entyMgr->getEventManager()->addEventListener([Events::preRemove, Events::postRemove, Events::prePersist, Events::postPersist, Events::preUpdate, Events::postUpdate, Events::postLoad, Events::preFlush, Events::onFlush, Events::postFlush, Events::onClear], new EventListener($app));
         $app->broadcast(DoctrineReadyEvent::READY_EVENT, new DoctrineReadyEvent($entyMgr));
         return $entyMgr;
     };
     $app['db_conn'] = function ($app) {
         $app['entyMgr']->getConnection();
     };
     $app->lock(['entyMgr', 'db_conn', 'doctrine.annotation.driver']);
 }
 /**
  * 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);
 }