for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Doctrine\DBAL\Tools\Console\ConnectionProvider;
use Doctrine\DBAL\Connection;
use InvalidArgumentException;
use function sprintf;
class ArrayConnectionProvider implements ConnectionProvider
{
/** @var array<string, Connection> */
private $connections;
/** @var string */
private $defaultConnectionName;
/**
* @param array<string, Connection> $connections
*/
public function __construct(array $connections, string $defaultConnectionName)
$this->connections = $connections;
$this->defaultConnectionName = $defaultConnectionName;
}
public static function createFromSingleConnection(Connection $connection, string $name = 'default') : self
return new self([$name => $connection], $name);
public function getDefaultConnection() : Connection
return $this->getConnection($this->defaultConnectionName);
public function getConnection(string $name) : Connection
if (! isset($this->connections[$name])) {
throw new InvalidArgumentException(sprintf('Connection with name "%s" does not exist.', $name));
return $this->connections[$name];