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 string|false |
||
35 | */ |
||
36 | private $default; |
||
37 | |||
38 | /** |
||
39 | * @var array |
||
40 | */ |
||
41 | private static $connectionParams = [ |
||
42 | 'host' => 'host', |
||
43 | 'port' => 'port', |
||
44 | 'name' => 'dbname', |
||
45 | 'charset' => 'charset', |
||
46 | ]; |
||
47 | |||
48 | /** |
||
49 | * @param array $config |
||
50 | */ |
||
51 | public function __construct(array $config = []) |
||
55 | |||
56 | /** |
||
57 | * Gets a database connection by ID. |
||
58 | * |
||
59 | * @param string $id |
||
60 | * |
||
61 | * @throws JAQBException if the connection does not exist |
||
62 | * |
||
63 | * @return QueryBuilder |
||
64 | */ |
||
65 | public function get($id) |
||
79 | |||
80 | /** |
||
81 | * Gets the default database connection. |
||
82 | * |
||
83 | * @throws JAQBException if there is not a default connection |
||
84 | * |
||
85 | * @return QueryBuilder |
||
86 | */ |
||
87 | public function getDefault() |
||
126 | |||
127 | /** |
||
128 | * Adds a connection. |
||
129 | * |
||
130 | * @param string $id |
||
131 | * @param QueryBuilder $connection |
||
132 | * |
||
133 | * @throws InvalidArgumentException if a connection with the given ID already exists |
||
134 | * |
||
135 | * @return $this |
||
136 | */ |
||
137 | public function add($id, QueryBuilder $connection) |
||
148 | |||
149 | /** |
||
150 | * Builds a new query builder instance from a configuration. |
||
151 | * NOTE: This is not intended to be used outside of this class. |
||
152 | * |
||
153 | * @param array $config |
||
154 | * @param string $id |
||
155 | * |
||
156 | * @return QueryBuilder |
||
157 | */ |
||
158 | public function buildFromConfig(array $config, $id) |
||
175 | |||
176 | /** |
||
177 | * Builds a PDO DSN string from a JAQB connection configuration. |
||
178 | * |
||
179 | * @param array $config |
||
180 | * @param string $id configuration ID |
||
181 | * |
||
182 | * @throws JAQBException if the configuration is invalid |
||
183 | * |
||
184 | * @return string |
||
185 | */ |
||
186 | public function buildDsn(array $config, $id) |
||
203 | } |
||
204 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: