1 | <?php declare(strict_types=1); |
||
24 | final class ConnectionManager { |
||
25 | |||
26 | /** |
||
27 | * Map of named database connections |
||
28 | * @var array |
||
29 | */ |
||
30 | private $connections = []; |
||
31 | |||
32 | /** |
||
33 | * Class instance variable |
||
34 | * @var ConnectionManager|null |
||
35 | */ |
||
36 | private static $instance; |
||
37 | |||
38 | /** |
||
39 | * Private constructor to prevent multiple instances |
||
40 | * @codeCoverageIgnore |
||
41 | */ |
||
42 | private function __construct() |
||
45 | |||
46 | /** |
||
47 | * Private clone method to prevent cloning |
||
48 | * |
||
49 | * @throws DomainException |
||
50 | * @return void |
||
51 | */ |
||
52 | public function __clone() |
||
56 | |||
57 | /** |
||
58 | * Prevent serialization of this object |
||
59 | * |
||
60 | * @throws DomainException |
||
61 | * @return void |
||
62 | */ |
||
63 | public function __sleep() |
||
67 | |||
68 | /** |
||
69 | * Make sure serialize/deserialize doesn't work |
||
70 | * |
||
71 | * @throws DomainException |
||
72 | * @return void |
||
73 | */ |
||
74 | public function __wakeup() |
||
78 | |||
79 | /** |
||
80 | * Return a connection manager instance |
||
81 | * |
||
82 | * @staticvar null $instance |
||
83 | * @return ConnectionManager |
||
84 | */ |
||
85 | public static function getInstance(): ConnectionManager |
||
94 | |||
95 | /** |
||
96 | * Returns the connection specified by the name given |
||
97 | * |
||
98 | * @param string|array|object $name |
||
99 | * @return QueryBuilderInterface |
||
100 | * @throws InvalidArgumentException |
||
101 | */ |
||
102 | public function getConnection($name = ''): QueryBuilderInterface |
||
117 | |||
118 | /** |
||
119 | * Parse the passed parameters and return a connection |
||
120 | * |
||
121 | * @param \stdClass $params |
||
122 | * @return QueryBuilderInterface |
||
123 | */ |
||
124 | public function connect(\stdClass $params): QueryBuilderInterface |
||
158 | |||
159 | /** |
||
160 | * Parses params into a dsn and option array |
||
161 | * |
||
162 | * @param \stdClass $params |
||
163 | * @return array |
||
164 | * @throws BadDBDriverException |
||
165 | */ |
||
166 | public function parseParams(\stdClass $params): array |
||
199 | |||
200 | /** |
||
201 | * Create the dsn from the db type and params |
||
202 | * |
||
203 | * @param string $dbtype |
||
204 | * @param \stdClass $params |
||
205 | * @return string |
||
206 | */ |
||
207 | private function createDsn(string $dbtype, \stdClass $params): string |
||
237 | } |