1 | <?php |
||
21 | class ConnectionManager |
||
22 | { |
||
23 | /** |
||
24 | * @var array |
||
25 | */ |
||
26 | private $config; |
||
27 | |||
28 | /** |
||
29 | * @var array |
||
30 | */ |
||
31 | private $connections = []; |
||
32 | |||
33 | /** |
||
34 | * @var array |
||
35 | */ |
||
36 | private static $connectionParams = [ |
||
37 | 'host' => 'host', |
||
38 | 'port' => 'port', |
||
39 | 'name' => 'dbname', |
||
40 | 'charset' => 'charset', |
||
41 | ]; |
||
42 | |||
43 | /** |
||
44 | * @param array $config |
||
45 | */ |
||
46 | public function __construct(array $config = []) |
||
50 | |||
51 | /** |
||
52 | * Gets a database connection by ID. |
||
53 | * |
||
54 | * @param string $id |
||
55 | * |
||
56 | * @throws JAQBException if the connection does not exist |
||
57 | * |
||
58 | * @return QueryBuilder |
||
59 | */ |
||
60 | public function get($id) |
||
74 | |||
75 | /** |
||
76 | * Gets the default database connection. |
||
77 | * |
||
78 | * @throws JAQBException if there is not a default connection |
||
79 | * |
||
80 | * @return QueryBuilder |
||
81 | */ |
||
82 | public function getDefault() |
||
90 | |||
91 | /** |
||
92 | * Adds a connection. |
||
93 | * |
||
94 | * @param string $id |
||
95 | * @param QueryBuilder $connection |
||
96 | * |
||
97 | * @throws InvalidArgumentException if a connection with the given ID already exists |
||
98 | * |
||
99 | * @return $this |
||
100 | */ |
||
101 | public function add($id, QueryBuilder $connection) |
||
111 | |||
112 | /** |
||
113 | * Builds a new query builder instance from a configuration. |
||
114 | * NOTE: This is not intended to be used outside of this class. |
||
115 | * |
||
116 | * @param array $config |
||
117 | * @param string $id |
||
118 | * |
||
119 | * @return QueryBuilder |
||
120 | */ |
||
121 | public function buildFromConfig(array $config, $id) |
||
142 | |||
143 | /** |
||
144 | * Builds a PDO DSN string from a JAQB connection configuration. |
||
145 | * |
||
146 | * @param array $config |
||
147 | * @param string $id configuration ID |
||
148 | * |
||
149 | * @throws JAQBException if the configuration is invalid |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | public function buildDsn(array $config, $id) |
||
170 | } |
||
171 |