-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3956 from dmaicher/cli_multi_connection
allow using multiple connections for CLI commands
- Loading branch information
Showing
8 changed files
with
193 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Doctrine\DBAL\Tools\Console; | ||
|
||
use OutOfBoundsException; | ||
|
||
final class ConnectionNotFound extends OutOfBoundsException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Doctrine\DBAL\Tools\Console; | ||
|
||
use Doctrine\DBAL\Connection; | ||
|
||
interface ConnectionProvider | ||
{ | ||
public function getDefaultConnection() : Connection; | ||
|
||
/** | ||
* @throws ConnectionNotFound in case a connection with the given name does not exist. | ||
*/ | ||
public function getConnection(string $name) : Connection; | ||
} |
37 changes: 37 additions & 0 deletions
37
lib/Doctrine/DBAL/Tools/Console/ConnectionProvider/SingleConnectionProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Doctrine\DBAL\Tools\Console\ConnectionProvider; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\Tools\Console\ConnectionNotFound; | ||
use Doctrine\DBAL\Tools\Console\ConnectionProvider; | ||
use function sprintf; | ||
|
||
class SingleConnectionProvider implements ConnectionProvider | ||
{ | ||
/** @var Connection */ | ||
private $connection; | ||
|
||
/** @var string */ | ||
private $defaultConnectionName; | ||
|
||
public function __construct(Connection $connection, string $defaultConnectionName = 'default') | ||
{ | ||
$this->connection = $connection; | ||
$this->defaultConnectionName = $defaultConnectionName; | ||
} | ||
|
||
public function getDefaultConnection() : Connection | ||
{ | ||
return $this->connection; | ||
} | ||
|
||
public function getConnection(string $name) : Connection | ||
{ | ||
if ($name !== $this->defaultConnectionName) { | ||
throw new ConnectionNotFound(sprintf('Connection with name "%s" does not exist.', $name)); | ||
} | ||
|
||
return $this->connection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters