1 | <?php |
||
17 | class DatabaseManager |
||
18 | { |
||
19 | /** |
||
20 | * The database connection factory instance. |
||
21 | * |
||
22 | * @var ConnectionFactory |
||
23 | */ |
||
24 | protected $factory; |
||
25 | |||
26 | /** |
||
27 | * The active connection instances. |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $connections = []; |
||
32 | |||
33 | /** |
||
34 | * The custom connection resolvers. |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | protected $extensions = []; |
||
39 | |||
40 | |||
41 | /** |
||
42 | * DatabaseManager constructor. |
||
43 | * |
||
44 | * @param $app |
||
45 | * @param ConnectionFactory $factory |
||
46 | */ |
||
47 | public function __construct($app, ConnectionFactory $factory) |
||
52 | |||
53 | /** |
||
54 | * Get a database connection instance. |
||
55 | * |
||
56 | * @param string $name |
||
57 | * @return \Childish\connection\Connection |
||
58 | */ |
||
59 | public function connection($name = null) |
||
76 | |||
77 | /** |
||
78 | * Parse the connection into an array of the name and read / write type. |
||
79 | * |
||
80 | * @param string $name |
||
81 | * @return array |
||
82 | */ |
||
83 | protected function parseConnectionName($name) |
||
90 | |||
91 | /** |
||
92 | * Make the database connection instance. |
||
93 | * |
||
94 | * @param string $name |
||
95 | * @return \Childish\connection\Connection |
||
96 | */ |
||
97 | protected function makeConnection($name) |
||
117 | |||
118 | /** |
||
119 | * Get the configuration for a connection. |
||
120 | * |
||
121 | * @param string $name |
||
122 | * @return array |
||
123 | * @throws \InvalidArgumentException |
||
124 | */ |
||
125 | protected function configuration($name) |
||
140 | |||
141 | /** |
||
142 | * Prepare the database connection instance. |
||
143 | * |
||
144 | * @param \Childish\connection\Connection $connection |
||
145 | * @param string $type |
||
146 | * @return \Childish\connection\Connection |
||
147 | */ |
||
148 | protected function configure(Connection $connection, $type) |
||
165 | |||
166 | /** |
||
167 | * Prepare the read / write mode for database connection instance. |
||
168 | * |
||
169 | * @param \Childish\connection\Connection $connection |
||
170 | * @param string $type |
||
171 | * @return \Childish\connection\Connection |
||
172 | */ |
||
173 | protected function setPdoForType(Connection $connection, $type = null) |
||
183 | |||
184 | /** |
||
185 | * Disconnect from the given database and remove from local cache. |
||
186 | * |
||
187 | * @param string $name |
||
188 | * @return void |
||
189 | */ |
||
190 | public function purge($name = null) |
||
198 | |||
199 | /** |
||
200 | * Disconnect from the given database. |
||
201 | * |
||
202 | * @param string $name |
||
203 | * @return void |
||
204 | */ |
||
205 | public function disconnect($name = null) |
||
211 | |||
212 | /** |
||
213 | * Reconnect to the given database. |
||
214 | * |
||
215 | * @param string $name |
||
216 | * @return \Childish\connection\Connection |
||
217 | */ |
||
218 | public function reconnect($name = null) |
||
228 | |||
229 | /** |
||
230 | * Refresh the PDO connections on a given connection. |
||
231 | * |
||
232 | * @param string $name |
||
233 | * @return \Childish\connection\Connection |
||
234 | */ |
||
235 | protected function refreshPdoConnections($name) |
||
243 | |||
244 | /** |
||
245 | * Get the default connection name. |
||
246 | * |
||
247 | * @return string |
||
248 | */ |
||
249 | public function getDefaultConnection() |
||
253 | |||
254 | /** |
||
255 | * Set the default connection name. |
||
256 | * |
||
257 | * @param string $name |
||
258 | * @return void |
||
259 | */ |
||
260 | public function setDefaultConnection($name) |
||
264 | |||
265 | /** |
||
266 | * Get all of the support drivers. |
||
267 | * |
||
268 | * @return array |
||
269 | */ |
||
270 | public function supportedDrivers() |
||
274 | |||
275 | /** |
||
276 | * Get all of the drivers that are actually available. |
||
277 | * |
||
278 | * @return array |
||
279 | */ |
||
280 | public function availableDrivers() |
||
287 | |||
288 | /** |
||
289 | * Register an extension connection resolver. |
||
290 | * |
||
291 | * @param string $name |
||
292 | * @param callable $resolver |
||
293 | * @return void |
||
294 | */ |
||
295 | public function extend($name, callable $resolver) |
||
299 | |||
300 | /** |
||
301 | * Return all of the created connections. |
||
302 | * |
||
303 | * @return array |
||
304 | */ |
||
305 | public function getConnections() |
||
309 | |||
310 | /** |
||
311 | * Dynamically pass methods to the default connection. |
||
312 | * |
||
313 | * @param string $method |
||
314 | * @param array $parameters |
||
315 | * @return mixed |
||
316 | */ |
||
317 | public function __call($method, $parameters) |
||
321 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: