getDriverClass example


    return $this->driverClasses[$class];
  }

  /** * Returns the database exceptions handler. * * @return \Drupal\Core\Database\ExceptionHandler * The database exceptions handler. */
  public function exceptionHandler() {
    $class = $this->getDriverClass('ExceptionHandler');
    return new $class();
  }

  /** * Prepares and returns a SELECT query object. * * @param string|\Drupal\Core\Database\Query\SelectInterface $table * The base table name or subquery for this query, used in the FROM clause. * If a string, the table specified will also be used as the "base" table * for query_alter hook implementations. * @param string $alias * (optional) The alias of the base table of this query. * @param $options * An array of options on the query. * * @return \Drupal\Core\Database\Query\SelectInterface * An appropriate SelectQuery object for this database connection. Note that * it may be a driver-specific subclass of SelectQuery, depending on the * driver. * * @see \Drupal\Core\Database\Query\Select */

  public function testGetDriverClass($expected$namespace$class) {
    $additional_class_loader = new ClassLoader();
    $additional_class_loader->addPsr4("Drupal\\corefake\\Driver\\Database\\corefake\\", __DIR__ . "/../../../../../tests/fixtures/database_drivers/module/corefake/src/Driver/Database/corefake");
    $additional_class_loader->addPsr4("Drupal\\corefake\\Driver\\Database\\corefakeWithAllCustomClasses\\", __DIR__ . "/../../../../../tests/fixtures/database_drivers/module/corefake/src/Driver/Database/corefakeWithAllCustomClasses");
    $additional_class_loader->register(TRUE);

    $mock_pdo = $this->createMock('Drupal\Tests\Core\Database\Stub\StubPDO');
    $connection = new StubConnection($mock_pdo['namespace' => $namespace]);
    $this->assertEquals($expected$connection->getDriverClass($class));
  }

  /** * Data provider for testSchema(). * * @return array * Array of arrays with the following elements: * - Expected namespaced class of schema object. * - Driver for PDO connection. * - Namespace for connection. */
  

  public function havingCompile(Connection $connection) {
    $this->having->compile($connection$this);
  }

  /** * {@inheritdoc} */
  public function extend($extender_name) {
    $parts = explode('\\', $extender_name);
    $class = end($parts);
    $driver_class = $this->connection->getDriverClass($class);
    if ($driver_class !== $class) {
      return new $driver_class($this$this->connection);
    }
    return new $extender_name($this$this->connection);
  }

  /** * {@inheritdoc} */
  public function havingIsNull($field) {
    $this->having->isNull($field);
    

  public function getDriverClass($class) {
    static $fixed_namespace;
    if (!$fixed_namespace) {
      // Override because we've altered the namespace in       // \Drupal\KernelTests\Core\Cache\EndOfTransactionQueriesTest::getDatabaseConnectionInfo()       // to use the logging Connection classes. Set to a proper database driver       // namespace.       $this->connectionOptions['namespace'] = (new \ReflectionClass(get_parent_class($this)))->getNamespaceName();
      $fixed_namespace = TRUE;
    }
    return parent::getDriverClass($class);
  }

  /** * Returns the executed queries. * * @return string[] */
  public function getLoggedStatements() {
    return $this->loggedStatements;
  }

}
$connectionOptions = $db->getConnectionOptions();

    // In the MySQL driver, the port can be different, so check individual     // options.     $this->assertEquals($connection_info['default']['driver']$connectionOptions['driver'], 'The default connection info driver matches the current connection options driver.');
    $this->assertEquals($connection_info['default']['database']$connectionOptions['database'], 'The default connection info database matches the current connection options database.');

    // Set up identical replica and confirm connection options are identical.     Database::addConnectionInfo('default', 'replica', $connection_info['default']);
    $db2 = Database::getConnection('replica', 'default');
    // Getting a driver class ensures the namespace option is set.     $this->assertEquals($db->getDriverClass('Select')$db2->getDriverClass('Select'));
    $connectionOptions2 = $db2->getConnectionOptions();

    // Get a fresh copy of the default connection options.     $connectionOptions = $db->getConnectionOptions();
    $this->assertSame($connectionOptions2$connectionOptions, 'The default and replica connection options are identical.');

    // Set up a new connection with different connection info.     $test = $connection_info['default'];
    $test['database'] .= 'test';
    Database::addConnectionInfo('test', 'default', $test);
    $connection_info = Database::getConnectionInfo('test');

    


  /** * {@inheritdoc} */
  public function extend($extender_name) {
    // We cannot call $this->query->extend(), because with multiple extenders     // you will replace all the earlier extenders with the last extender,     // instead of creating list of objects that extend each other.     $parts = explode('\\', $extender_name);
    $class = end($parts);
    $driver_class = $this->connection->getDriverClass($class);
    if ($driver_class !== $class) {
      return new $driver_class($this$this->connection);
    }
    return new $extender_name($this$this->connection);
  }

  /* Alter accessors to expose the query data to alter hooks. */

  /** * {@inheritdoc} */
  
Home | Imprint | This part of the site doesn't use cookies.