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 | * @param array $options |
||
39 | * @param bool $forceNew |
||
40 | * |
||
41 | * @return Connection |
||
42 | */ |
||
43 | public function connect($dsn, $username = '', $password = '', array $options = [], $forceNew = false) |
||
60 | |||
61 | /** |
||
62 | * Close the connection. If no connection is passed, it closes the last. |
||
63 | * |
||
64 | * @param Connection|null $connection |
||
65 | * |
||
66 | * @return bool |
||
67 | * |
||
68 | * @throws NoConnectionException |
||
69 | */ |
||
70 | public function disconnect(Connection $connection = null) |
||
82 | |||
83 | /** |
||
84 | * Get a connection. |
||
85 | * |
||
86 | * @param string $id |
||
87 | * |
||
88 | * @return Connection |
||
89 | */ |
||
90 | public function getConnection($id) |
||
96 | |||
97 | /** |
||
98 | * Select the database to use. If the connection is omitted, the last one is used. |
||
99 | * |
||
100 | * @param $databaseName |
||
101 | * @param Connection|null $connection |
||
102 | * |
||
103 | * @return bool |
||
104 | */ |
||
105 | public function useDatabase($databaseName, Connection $connection = null) |
||
112 | |||
113 | /** |
||
114 | * Execute a query. If the connection is omitted, the last one is used. |
||
115 | * |
||
116 | * @param $query |
||
117 | * @param Connection|null $connection |
||
118 | * |
||
119 | * @return mixed |
||
120 | */ |
||
121 | public function query($query, Connection $connection = null) |
||
127 | |||
128 | /** |
||
129 | * Return the last used connection. |
||
130 | * |
||
131 | * @return Connection |
||
132 | * |
||
133 | * @throws NoConnectionException |
||
134 | */ |
||
135 | public function getLastConnection() |
||
145 | |||
146 | public function getOpenConnectionOrFail(Connection $connection = null) |
||
154 | |||
155 | public function checkConnection(Connection $connection) |
||
163 | |||
164 | public function getConnections() |
||
168 | |||
169 | public function setLastConnection($id) |
||
182 | |||
183 | public function addConnection($id, Connection $connection) |
||
193 | } |
||
194 |