GdprSqlBase.php in General Data Protection Regulation 8.2
File
modules/gdpr_dump/src/Sql/GdprSqlBase.php
View source
<?php
namespace Drupal\gdpr_dump\Sql;
use Drupal\Core\Database\Database;
use Drush\Drush;
use Drush\Sql\SqlBase;
use RuntimeException;
use function array_key_exists;
use function is_array;
class GdprSqlBase extends SqlBase {
public static function create($options = []) {
$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])) {
$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.'));
}
public static function getInstance($dbSpec, $options) {
$driver = $dbSpec['driver'];
$className = 'Drupal\\gdpr_dump\\Sql\\GdprSql' . ucfirst($driver);
$instance = new $className($dbSpec, $options);
$instance
->setConfig(Drush::service('config'));
return $instance;
}
}