1 | <?php |
||
25 | final class ConnectionManager { |
||
26 | |||
27 | /** |
||
28 | * Map of named database connections |
||
29 | * @var array |
||
30 | */ |
||
31 | private $connections = []; |
||
32 | |||
33 | /** |
||
34 | * Class instance variable |
||
35 | * @var ConnectionManager |
||
36 | */ |
||
37 | private static $instance = NULL; |
||
38 | |||
39 | // -------------------------------------------------------------------------- |
||
40 | |||
41 | /** |
||
42 | * Private constructor to prevent multiple instances |
||
43 | * @codeCoverageIgnore |
||
44 | */ |
||
45 | private function __construct() |
||
48 | |||
49 | // -------------------------------------------------------------------------- |
||
50 | |||
51 | /** |
||
52 | * Private clone method to prevent cloning |
||
53 | * @throws \DomainException |
||
54 | */ |
||
55 | public function __clone() |
||
59 | |||
60 | // -------------------------------------------------------------------------- |
||
61 | |||
62 | /** |
||
63 | * Prevent serialization of this object |
||
64 | * @throws \DomainException |
||
65 | */ |
||
66 | public function __sleep() |
||
70 | |||
71 | // -------------------------------------------------------------------------- |
||
72 | |||
73 | /** |
||
74 | * Make sure serialize/deserialize doesn't work |
||
75 | * @throws \DomainException |
||
76 | */ |
||
77 | public function __wakeup() |
||
81 | |||
82 | // -------------------------------------------------------------------------- |
||
83 | |||
84 | /** |
||
85 | * Return a connection manager instance |
||
86 | * |
||
87 | * @staticvar null $instance |
||
88 | * @return ConnectionManager |
||
89 | */ |
||
90 | public static function get_instance() |
||
99 | |||
100 | // -------------------------------------------------------------------------- |
||
101 | |||
102 | /** |
||
103 | * Returns the connection specified by the name given |
||
104 | * |
||
105 | * @param string|array|object $name |
||
106 | * @return QueryBuilder |
||
107 | * @throws \InvalidArgumentException |
||
108 | */ |
||
109 | public function get_connection($name = '') |
||
124 | |||
125 | // -------------------------------------------------------------------------- |
||
126 | |||
127 | /** |
||
128 | * Parse the passed parameters and return a connection |
||
129 | * |
||
130 | * @param \stdClass $params |
||
131 | * @return QueryBuilder |
||
132 | */ |
||
133 | public function connect(\stdClass $params) |
||
167 | |||
168 | // -------------------------------------------------------------------------- |
||
169 | |||
170 | /** |
||
171 | * Parses params into a dsn and option array |
||
172 | * |
||
173 | * @param \stdClass $params |
||
174 | * @return array |
||
175 | * @throws BadDBDriverException |
||
176 | */ |
||
177 | public function parse_params(\stdClass $params) |
||
218 | |||
219 | // -------------------------------------------------------------------------- |
||
220 | |||
221 | /** |
||
222 | * Create the dsn from the db type and params |
||
223 | * |
||
224 | * @param string $dbtype |
||
225 | * @param \stdClass $params |
||
226 | * @return string |
||
227 | */ |
||
228 | private function create_dsn($dbtype, \stdClass $params) |
||
263 | } |
||
264 | // End of connection_manager.php |