1 | <?php |
||
9 | class MasterSlavesConnection implements Connection, ConnectionWrapper |
||
10 | { |
||
11 | private $master; |
||
12 | private $slavesWeights; |
||
13 | private $connection; |
||
14 | private $driver; |
||
15 | private $currentConnectionFactory; |
||
16 | |||
17 | /** |
||
18 | * @param Closure $master |
||
19 | * @param SplObjectStorage $slavesWeights |
||
20 | */ |
||
21 | public function __construct($master, SplObjectStorage $slavesWeights) |
||
27 | |||
28 | private function checkSlavesWeights(SplObjectStorage $slavesWeights) |
||
36 | |||
37 | public function connectToMaster() |
||
42 | |||
43 | public function connectToSlave() |
||
48 | |||
49 | public function isConnectedToMaster() |
||
53 | |||
54 | private function connection() |
||
61 | |||
62 | /** |
||
63 | * @inherit |
||
64 | */ |
||
65 | public function getCurrentConnection() |
||
69 | |||
70 | /** |
||
71 | * @inherit |
||
72 | */ |
||
73 | public function wrappedConnection() |
||
80 | |||
81 | public function wrappedDriver() |
||
88 | |||
89 | private function wrap() |
||
99 | |||
100 | private function chooseASlave() |
||
114 | |||
115 | private function totalSlavesWeight() |
||
123 | |||
124 | public function disableCurrentSlave() |
||
130 | |||
131 | public function slaves() |
||
135 | |||
136 | /** |
||
137 | * Prepares a statement for execution and returns a Statement object. |
||
138 | * |
||
139 | * @param string $prepareString |
||
140 | * |
||
141 | * @return \Doctrine\DBAL\Driver\Statement |
||
142 | */ |
||
143 | public function prepare($prepareString) |
||
148 | |||
149 | /** |
||
150 | * Executes an SQL statement, returning a result set as a Statement object. |
||
151 | * |
||
152 | * @return \Doctrine\DBAL\Driver\Statement |
||
153 | */ |
||
154 | public function query() |
||
158 | |||
159 | /** |
||
160 | * Quotes a string for use in a query. |
||
161 | * |
||
162 | * @param string $input |
||
163 | * @param integer $type |
||
164 | * |
||
165 | * @return string |
||
166 | */ |
||
167 | public function quote($input, $type = \PDO::PARAM_STR) |
||
171 | |||
172 | /** |
||
173 | * Executes an SQL statement and return the number of affected rows. |
||
174 | * |
||
175 | * @param string $statement |
||
176 | * |
||
177 | * @return integer |
||
178 | */ |
||
179 | public function exec($statement) |
||
184 | |||
185 | /** |
||
186 | * Returns the ID of the last inserted row or sequence value. |
||
187 | * |
||
188 | * @param string|null $name |
||
189 | * |
||
190 | * @return string |
||
191 | */ |
||
192 | public function lastInsertId($name = null) |
||
196 | |||
197 | /** |
||
198 | * Initiates a transaction. |
||
199 | * |
||
200 | * @return boolean TRUE on success or FALSE on failure. |
||
201 | */ |
||
202 | public function beginTransaction() |
||
207 | |||
208 | /** |
||
209 | * Commits a transaction. |
||
210 | * |
||
211 | * @return boolean TRUE on success or FALSE on failure. |
||
212 | */ |
||
213 | public function commit() |
||
218 | |||
219 | /** |
||
220 | * Rolls back the current transaction, as initiated by beginTransaction(). |
||
221 | * |
||
222 | * @return boolean TRUE on success or FALSE on failure. |
||
223 | */ |
||
224 | public function rollBack() |
||
229 | |||
230 | /** |
||
231 | * Returns the error code associated with the last operation on the database handle. |
||
232 | * |
||
233 | * @return string|null The error code, or null if no operation has been run on the database handle. |
||
234 | */ |
||
235 | public function errorCode() |
||
239 | |||
240 | /** |
||
241 | * Returns extended error information associated with the last operation on the database handle. |
||
242 | * |
||
243 | * @return array |
||
244 | */ |
||
245 | public function errorInfo() |
||
249 | } |
||
250 |