5 * Contains Drupal\Console\Command\Shared\ConnectTrait.
8 namespace Drupal\Console\Command\Shared;
10 use Drupal\Core\Database\Database;
14 protected $supportedDrivers = ['mysql','pgsql'];
16 public function resolveConnection($database = 'default')
18 $connectionInfo = Database::getConnectionInfo();
20 if (!$connectionInfo || !isset($connectionInfo[$database])) {
21 $this->getIo()->error(
23 $this->trans('commands.database.connect.messages.database-not-found'),
31 $databaseConnection = $connectionInfo[$database];
32 if (!in_array($databaseConnection['driver'], $this->supportedDrivers)) {
33 $this->getIo()->error(
35 $this->trans('commands.database.connect.messages.database-not-supported'),
36 $databaseConnection['driver']
43 return $databaseConnection;
46 public function getRedBeanConnection($database = 'default')
48 $connectionInfo = Database::getConnectionInfo();
49 $databaseConnection = $connectionInfo[$database];
50 if ($databaseConnection['driver'] == 'mysql') {
52 'mysql:host=%s;dbname=%s',
53 $databaseConnection['host'],
54 $databaseConnection['database']
57 $this->redBean->setup(
59 $databaseConnection['username'],
60 $databaseConnection['password'],
64 return $this->redBean;