You are here

Connection.php in MongoDB 8

File

drivers/lib/Drupal/Driver/Database/mongodb/Connection.php
View source
<?php

namespace Drupal\Driver\Database\mongodb;

use Drupal\Core\Database\Driver\fake\FakeConnection;
use Drupal\Core\Database\Driver\fake\FakeInsert;
use Drupal\Core\Database\Driver\fake\FakeUpdate;
use Drupal\mongodb\MongoCollectionFactory;
class Connection extends FakeConnection {
  protected $transactionSupport = FALSE;
  protected $testHelper;
  public function __construct(MongoCollectionFactory $mongo) {
    $this->mongo = $mongo;

    // Connection::destroy needs a connection object.
    $this->connection = new DoNothing();
    return parent::__construct([], [
      'namespace' => __NAMESPACE__,
    ]);
  }
  public function version() {
    return phpversion('mongo');
  }
  public static function open(array &$connection_options = array()) {
    $mongo_info['servers']['default']['server'] = $connection_options['database'];
    return new MongoCollectionFactory($mongo_info);
  }
  public function schema() {
    return new Schema();
  }
  public function startTransaction($name = '') {
    return new DoNothing();
  }
  public function nextId($existing_id = 0) {
    return \Drupal::service('mongo')
      ->nextId('generic', $existing_id);
  }
  public function driver() {
    return 'mongodb';
  }
  public function insert($table, array $options = array()) {
    $return = FALSE;
    if (drupal_valid_test_ua() || $table == 'node_access') {
      $return = $this
        ->getTestHelper()
        ->insert($table, $options);
    }
    return $return ?: new FakeInsert($table, $options);
  }
  public function query($query, array $args = array(), $options = array()) {
    if (drupal_valid_test_ua()) {
      return $this
        ->getTestHelper()
        ->query($query, $args, $options);
    }
    return parent::query($query, $args, $options);

    // TODO: Change the autogenerated stub
  }

  /**
   * {@inheritdoc}
   */
  public function update($table, array $options = array()) {
    $return = FALSE;
    if (drupal_valid_test_ua()) {
      $return = $this
        ->getTestHelper()
        ->update($table, $options);
    }
    return $return ?: new FakeUpdate($this->databaseContents, $table);
  }

  /**
   * {@inheritdoc}
   */
  public function select($table, $alias = NULL, array $options = array()) {
    $return = FALSE;
    if (drupal_valid_test_ua()) {
      $return = $this
        ->getTestHelper()
        ->select($table, $alias, $options);
    }
    return $return ?: new FakeUpdate($this->databaseContents, $table);
  }

  /**
   * @return TestHelper
   */
  public function getTestHelper() {
    if (!isset($this->testHelper)) {
      $this->testHelper = new DbHelper($this->mongo);
    }
    return $this->testHelper;
  }

}

Classes

Namesort descending Description
Connection