1 | <?php |
||
8 | class Manager |
||
9 | { |
||
10 | /** |
||
11 | * The array of open connections. |
||
12 | * |
||
13 | * @var array |
||
14 | */ |
||
15 | protected $connections = []; |
||
16 | |||
17 | /** |
||
18 | * @var ConnectionFactory |
||
19 | */ |
||
20 | protected $connectionFactory; |
||
21 | |||
22 | /** |
||
23 | * Create a Manager instance. |
||
24 | * |
||
25 | * @param ConnectionFactory $connectionFactory |
||
26 | */ |
||
27 | public function __construct(ConnectionFactory $connectionFactory) |
||
31 | |||
32 | /** |
||
33 | * Return a connection to the database, creating a new one if needed. |
||
34 | * |
||
35 | * @param string $dsn |
||
36 | * @param string $username |
||
37 | * @param string $password |
||
38 | * @return Connection |
||
39 | */ |
||
40 | public function connect($dsn, $username = '', $password = '') |
||
57 | |||
58 | /** |
||
59 | * Close the connection. If no connection is passed, it closes the last. |
||
60 | * |
||
61 | * @param Connection|null $connection |
||
62 | * @return bool |
||
63 | * @throws NoConnectionException |
||
64 | */ |
||
65 | public function disconnect(Connection $connection = null) |
||
77 | |||
78 | /** |
||
79 | * Get a connection. |
||
80 | * |
||
81 | * @param string $id |
||
82 | * @return Connection |
||
83 | */ |
||
84 | public function getConnection($id) |
||
90 | |||
91 | /** |
||
92 | * Select the database to use. If the connection is omitted, the last one is used. |
||
93 | * |
||
94 | * @param $databaseName |
||
95 | * @param Connection|null $connection |
||
96 | * @return bool |
||
97 | */ |
||
98 | public function useDatabase($databaseName, Connection $connection = null) |
||
105 | |||
106 | /** |
||
107 | * Execute a query. If the connection is omitted, the last one is used. |
||
108 | * |
||
109 | * @param $query |
||
110 | * @param Connection|null $connection |
||
111 | * @return mixed |
||
112 | */ |
||
113 | public function query($query, Connection $connection = null) |
||
119 | |||
120 | /** |
||
121 | * Return the last used connection. |
||
122 | * |
||
123 | * @return Connection |
||
124 | * @throws NoConnectionException |
||
125 | */ |
||
126 | public function getLastConnection() |
||
136 | |||
137 | public function getOpenConnectionOrFail(Connection $connection = null) |
||
145 | |||
146 | public function checkConnection(Connection $connection) |
||
154 | |||
155 | public function getConnections() |
||
159 | |||
160 | public function setLastConnection($id) |
||
168 | |||
169 | public function addConnection($id, Connection $connection) |
||
173 | } |
||
174 |