getConnection() public method

Gets the PHP Mongo instance that this DocumentManager wraps.
public getConnection ( ) : Connection
return Doctrine\MongoDB\Connection
 /**
  * {@inheritdoc}
  */
 protected function initDB()
 {
     if (is_null($this->collection)) {
         $databaseName = $this->dm->getConfiguration()->getDefaultDB();
         $collection = $this->dm->getConnection()->selectCollection($databaseName, $this->options['collection']);
         $this->collection = $collection;
     }
     return $this->collection;
 }
Beispiel #2
0
 public function tearDown()
 {
     if (!$this->dm) {
         return;
     }
     $collections = $this->dm->getConnection()->selectDatabase(DOCTRINE_MONGODB_DATABASE)->listCollections();
     foreach ($collections as $collection) {
         $collection->drop();
     }
 }
 /**
  * DocumentManager mock object together with
  * annotation mapping driver and database
  *
  * @param EventManager $evm
  * @return DocumentManager
  */
 protected function getMockDocumentManager(EventManager $evm = null, $config = null)
 {
     $conn = new Connection();
     $config = $config ? $config : $this->getMockAnnotatedConfig();
     try {
         $this->dm = DocumentManager::create($conn, $config, $evm ?: $this->getEventManager());
         $this->dm->getConnection()->connect();
     } catch (\MongoException $e) {
         $this->markTestSkipped('Doctrine MongoDB ODM failed to connect');
     }
     return $this->dm;
 }
Beispiel #4
0
 /**
  * Wraps the supplied base cursor as an ODM one.
  *
  * @param Doctrine\MongoDB\Cursor $cursor The base cursor
  *
  * @return Cursor An ODM cursor
  */
 private function wrapCursor(BaseCursor $cursor)
 {
     if ($cursor instanceof BaseLoggableCursor) {
         return new LoggableCursor($this->dm->getConnection(), $this->collection, $this->dm->getUnitOfWork(), $this->class, $cursor, $cursor->getQuery(), $cursor->getFields(), $this->dm->getConfiguration()->getRetryQuery(), $cursor->getLoggerCallable());
     } else {
         return new Cursor($this->dm->getConnection(), $this->collection, $this->dm->getUnitOfWork(), $this->class, $cursor, $cursor->getQuery(), $cursor->getFields(), $this->dm->getConfiguration()->getRetryQuery());
     }
 }
Beispiel #5
0
 public function setUp()
 {
     Type::hasType('object') ? Type::overrideType('object', 'Payum\\Core\\Bridge\\Doctrine\\Types\\ObjectType') : Type::addType('object', 'Payum\\Core\\Bridge\\Doctrine\\Types\\ObjectType');
     $config = new Configuration();
     $config->setProxyDir(\sys_get_temp_dir());
     $config->setProxyNamespace('PayumTestsProxies');
     $config->setHydratorDir(\sys_get_temp_dir());
     $config->setHydratorNamespace('PayumTestsHydrators');
     $config->setMetadataDriverImpl($this->getMetadataDriverImpl($config));
     $config->setMetadataCacheImpl(new ArrayCache());
     $config->setDefaultDB('payum_tests');
     $connection = new Connection(null, array(), $config);
     $this->dm = DocumentManager::create($connection, $config);
     foreach ($this->dm->getConnection()->selectDatabase('payum_tests')->listCollections() as $collection) {
         $collection->drop();
     }
 }
Beispiel #6
0
 /**
  * @param $documentName
  *
  * @return array
  */
 private function runShardCollectionCommand($documentName)
 {
     $class = $this->dm->getClassMetadata($documentName);
     $dbName = $this->dm->getDocumentDatabase($documentName)->getName();
     $shardKey = $class->getShardKey();
     $adminDb = $this->dm->getConnection()->selectDatabase('admin');
     $result = $adminDb->command(array('shardCollection' => $dbName . '.' . $class->getCollection(), 'key' => $shardKey['keys']), $shardKey['options']);
     return $result;
 }
 /**
  * {@inheritDoc}
  */
 public function save_run($xhprof_data, $type, $run_id = null)
 {
     if (!class_exists('\\Xhgui_Profiles') || !class_exists('\\Xhgui_Saver_Mongo')) {
         throw new \Exception('composer require perftools/xhgui dev-master');
     }
     $data = $this->prepareForSave($xhprof_data);
     $dbname = $this->documentManager->getConfiguration()->getDefaultDB();
     $mongo = $this->documentManager->getConnection()->getMongoClient()->selectDB($dbname);
     $profiles = new \Xhgui_Profiles($mongo);
     $saver = new \Xhgui_Saver_Mongo($profiles);
     try {
         $saver->save($data);
         $run_id = (string) $data['_id'];
     } catch (\Exception $e) {
         error_log($e->getMessage());
     }
     return $run_id;
 }
Beispiel #8
0
 private function wrapCursor(BaseCursor $baseCursor, array $hints)
 {
     if ($baseCursor instanceof BaseLoggableCursor) {
         $cursor = new LoggableCursor($this->dm->getConnection(), $this->collection, $this->dm->getUnitOfWork(), $this->class, $baseCursor, $baseCursor->getQuery(), $baseCursor->getFields(), $this->dm->getConfiguration()->getRetryQuery(), $baseCursor->getLoggerCallable());
     } else {
         $cursor = new Cursor($this->dm->getConnection(), $this->collection, $this->dm->getUnitOfWork(), $this->class, $baseCursor, $baseCursor->getQuery(), $baseCursor->getFields(), $this->dm->getConfiguration()->getRetryQuery());
     }
     $cursor->hydrate($this->hydrate);
     $cursor->setHints($hints);
     return $cursor;
 }
Beispiel #9
0
 public function setUp()
 {
     $this->skipTestsIfPhp7();
     if (false == (class_exists(\MongoId::class) && class_exists(Connection::class))) {
         $this->markTestSkipped('Either mongo extension or\\and doctrine\\mongo-odm are not installed.');
     }
     Type::hasType('object') ? Type::overrideType('object', 'Payum\\Core\\Bridge\\Doctrine\\Types\\ObjectType') : Type::addType('object', 'Payum\\Core\\Bridge\\Doctrine\\Types\\ObjectType');
     $config = new Configuration();
     $config->setProxyDir(\sys_get_temp_dir());
     $config->setProxyNamespace('PayumTestsProxies');
     $config->setHydratorDir(\sys_get_temp_dir());
     $config->setHydratorNamespace('PayumTestsHydrators');
     $config->setMetadataDriverImpl($this->getMetadataDriverImpl($config));
     $config->setMetadataCacheImpl(new ArrayCache());
     $config->setDefaultDB('payum_tests');
     $connection = new Connection(null, array(), $config);
     $this->dm = DocumentManager::create($connection, $config);
     foreach ($this->dm->getConnection()->selectDatabase('payum_tests')->listCollections() as $collection) {
         $collection->drop();
     }
 }
 /**
  * @param $logger
  *
  * @return DocumentManager
  */
 private function getNewDmWithLogger($logger)
 {
     $this->dm->getConfiguration()->setLoggerCallable($logger);
     $dm = DocumentManager::create($this->dm->getConnection(), $this->dm->getConfiguration());
     return $dm;
 }
Beispiel #11
0
 protected function getServerVersion()
 {
     $result = $this->dm->getConnection()->selectDatabase(DOCTRINE_MONGODB_DATABASE)->command(array('buildInfo' => 1));
     return $result['version'];
 }