You are here

public static function GdprSqlBase::create in General Data Protection Regulation 8.2

Same name and namespace in other branches
  1. 3.0.x modules/gdpr_dump/src/Sql/GdprSqlBase.php \Drupal\gdpr_dump\Sql\GdprSqlBase::create()

Get a driver specific instance of this class.

Parameters

mixed $options: An options array as handed to a command callback.

Return value

\Drush\Sql\SqlBase The instance.

Throws

\Exception

1 call to GdprSqlBase::create()
GdprSqlDump::getInstance in modules/gdpr_dump/src/Service/GdprSqlDump.php
Get a SqlBase instance according to dbSpecs.

File

modules/gdpr_dump/src/Sql/GdprSqlBase.php, line 32

Class

GdprSqlBase
Class GdprSqlBase.

Namespace

Drupal\gdpr_dump\Sql

Code

public static function create($options = []) {

  // Set defaults in the unfortunate event that caller doesn't provide values.
  $options += [
    'database' => 'default',
    'target' => 'default',
    'db-url' => NULL,
    'databases' => NULL,
    'db-prefix' => NULL,
  ];
  $database = $options['database'];
  $target = $options['target'];
  if ($url = $options['db-url']) {
    $url = is_array($url) ? $url[$database] : $url;
    $dbSpec = self::dbSpecFromDbUrl($url);
    $dbSpec['db_prefix'] = $options['db-prefix'];
    return self::getInstance($dbSpec, $options);
  }
  if (($databases = $options['databases']) && array_key_exists($database, $databases) && array_key_exists($target, $databases[$database])) {

    // @todo 'databases' option is not declared anywhere?
    $dbSpec = $databases[$database][$target];
    return self::getInstance($dbSpec, $options);
  }
  if ($info = Database::getConnectionInfo($database)) {
    $dbSpec = $info[$target];
    return self::getInstance($dbSpec, $options);
  }
  throw new RuntimeException(dt('Unable to load Drupal settings. Check your --root, --uri, etc.'));
}