createConnectionOptionsFromUrl example

public function getFullQualifiedTableName($table) {
    $prefix = $this->getPrefix();

    // Don't include the SQLite database file name as part of the table name.     return $prefix . $table;
  }

  /** * {@inheritdoc} */
  public static function createConnectionOptionsFromUrl($url$root) {
    $database = parent::createConnectionOptionsFromUrl($url$root);

    // A SQLite database path with two leading slashes indicates a system path.     // Otherwise the path is relative to the Drupal root.     $url_components = parse_url($url);
    if ($url_components['path'][0] === '/') {
      $url_components['path'] = substr($url_components['path'], 1);
    }
    if ($url_components['path'][0] === '/' || $url_components['path'] === ':memory:') {
      $database['database'] = $url_components['path'];
    }
    else {
      

  public function testCreateConnectionOptionsFromUrl(string $url, string $expected) {
    $root = dirname(__DIR__, 8);
    $sqlite_connection = new Connection($this->createMock(StubPDO::class)[]);
    $database = $sqlite_connection->createConnectionOptionsFromUrl($url$root);
    $this->assertEquals('sqlite', $database['driver']);
    $this->assertEquals($expected$database['database']);
  }

  /** * Data provider for testCreateConnectionOptionsFromUrl. * * @return string[][] * Associative array of arrays with the following elements: * - SQLite database URL * - Expected database connection option */
if (!$module) {
      // Determine the connection class to use. Discover if the URL has a valid       // driver scheme for a Drupal 8 style custom driver.       // @todo Remove this in Drupal 10.       $connection_class = "Drupal\\Driver\\Database\\{$driver}\\Connection";
    }

    if (!class_exists($connection_class)) {
      throw new \InvalidArgumentException("Can not convert '$url' to a database connection, class '$connection_class' does not exist");
    }

    $options = $connection_class::createConnectionOptionsFromUrl($url$root);

    // If the driver is provided by a module add the necessary information to     // autoload the code.     // @see \Drupal\Core\Site\Settings::initialize()     if (isset($psr4_base_directory)) {
      $options['autoload'] = $psr4_base_directory;
    }

    return $options;
  }

  
Home | Imprint | This part of the site doesn't use cookies.