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