5 * Contains Drupal\Console\Command\Shared\ConnectTrait.
8 namespace Drupal\Console\Command\Shared;
10 use Drupal\Console\Core\Style\DrupalStyle;
11 use Drupal\Core\Database\Database;
15 protected $supportedDrivers = ['mysql','pgsql'];
17 public function resolveConnection(DrupalStyle $io, $database = 'default')
19 $connectionInfo = Database::getConnectionInfo();
21 if (!$connectionInfo || !isset($connectionInfo[$database])) {
24 $this->trans('commands.database.connect.messages.database-not-found'),
32 $databaseConnection = $connectionInfo[$database];
33 if (!in_array($databaseConnection['driver'], $this->supportedDrivers)) {
36 $this->trans('commands.database.connect.messages.database-not-supported'),
37 $databaseConnection['driver']
44 return $databaseConnection;
47 public function getRedBeanConnection($database = 'default')
49 $connectionInfo = Database::getConnectionInfo();
50 $databaseConnection = $connectionInfo[$database];
51 if ($databaseConnection['driver'] == 'mysql') {
53 'mysql:host=%s;dbname=%s',
54 $databaseConnection['host'],
55 $databaseConnection['database']
58 $this->redBean->setup(
60 $databaseConnection['username'],
61 $databaseConnection['password'],
65 return $this->redBean;