1 | <?php |
||
30 | class Pdo implements StorageInterface |
||
|
|||
31 | { |
||
32 | use DataTypeCasterTrait; |
||
33 | |||
34 | /** |
||
35 | * @var PhpPdo |
||
36 | */ |
||
37 | protected $conn; |
||
38 | |||
39 | /** |
||
40 | * @var PdoConfig |
||
41 | */ |
||
42 | protected $config; |
||
43 | |||
44 | /** |
||
45 | * @var array |
||
46 | */ |
||
47 | protected $quoteMaps = array('mysql' => '`', 'pgsql' => '"'); |
||
48 | |||
49 | /** |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $quote = '`'; |
||
53 | |||
54 | /** |
||
55 | * @var int |
||
56 | */ |
||
57 | protected $transactionLevel = 0; |
||
58 | |||
59 | /** |
||
60 | * @var bool |
||
61 | */ |
||
62 | protected $transactional = false; |
||
63 | |||
64 | /** |
||
65 | * Constructor. |
||
66 | * |
||
67 | * @param PdoConfig $config |
||
68 | */ |
||
69 | public function __construct(PdoConfig $config) |
||
84 | |||
85 | /** |
||
86 | * {@inheritdoc} |
||
87 | */ |
||
88 | public function save(ReadModelInterface $model, $table) |
||
105 | |||
106 | /** |
||
107 | * {@inheritdoc} |
||
108 | */ |
||
109 | public function remove($id, $table) |
||
114 | |||
115 | /** |
||
116 | * {@inheritdoc} |
||
117 | */ |
||
118 | public function findById($id, $table, $class) |
||
124 | |||
125 | /** |
||
126 | * {@inheritdoc} |
||
127 | */ |
||
128 | public function finder($table, $class) |
||
132 | |||
133 | /** |
||
134 | * Execute query without statement. |
||
135 | * |
||
136 | * @param string $sql |
||
137 | * @param array $values |
||
138 | */ |
||
139 | public function exec($sql, array $values = array()) |
||
157 | |||
158 | /** |
||
159 | * Execute query with statement. |
||
160 | * |
||
161 | * @param string $sql |
||
162 | * @param int $mode |
||
163 | * |
||
164 | * @return PDOStatement |
||
165 | */ |
||
166 | public function query($sql, $mode = PhpPdo::FETCH_ASSOC) |
||
174 | |||
175 | /** |
||
176 | * @return int |
||
177 | */ |
||
178 | public function getTransactionLevel() |
||
182 | |||
183 | /** |
||
184 | * @return boolean |
||
185 | */ |
||
186 | public function isTransactional() |
||
190 | |||
191 | /** |
||
192 | * Begin transaction |
||
193 | */ |
||
194 | public function beginTransaction() |
||
203 | |||
204 | /** |
||
205 | * Rollback transaction |
||
206 | */ |
||
207 | public function rollback() |
||
213 | |||
214 | /** |
||
215 | * Commit transaction. |
||
216 | */ |
||
217 | public function commit() |
||
225 | |||
226 | /** |
||
227 | * Compute fields to expressions. |
||
228 | * |
||
229 | * @param array $fields |
||
230 | * @param PdoFinder $finder |
||
231 | * |
||
232 | * @return PdoCompositeExpression |
||
233 | */ |
||
234 | protected function computeFieldsExpression(array $fields, PdoFinder $finder) |
||
243 | |||
244 | /** |
||
245 | * Normalize value. |
||
246 | * |
||
247 | * @param array $values |
||
248 | * |
||
249 | * @return array |
||
250 | */ |
||
251 | protected function normalize(array $values) |
||
272 | |||
273 | /** |
||
274 | * Build query update. |
||
275 | * |
||
276 | * @param array $values |
||
277 | * @param array $conditions |
||
278 | * @param string $table |
||
279 | * |
||
280 | * @return string |
||
281 | */ |
||
282 | protected function buildUpdateQuery(array $values, array $conditions, $table) |
||
292 | |||
293 | /** |
||
294 | * Build insert query. |
||
295 | * |
||
296 | * @param array $values |
||
297 | * @param string $table |
||
298 | * |
||
299 | * @return string |
||
300 | */ |
||
301 | public function buildInsertQuery(array $values, $table) |
||
310 | |||
311 | /** |
||
312 | * Build data sets. |
||
313 | * |
||
314 | * @param array $parts |
||
315 | * |
||
316 | * @return array |
||
317 | */ |
||
318 | protected function buildDataSets(array $parts) |
||
327 | |||
328 | /** |
||
329 | * Quote field. |
||
330 | * |
||
331 | * @param string $field |
||
332 | * |
||
333 | * @return string |
||
334 | */ |
||
335 | protected function quote($field) |
||
339 | |||
340 | /** |
||
341 | * @param mixed $value |
||
342 | * |
||
343 | * @return mixed|null|string |
||
344 | */ |
||
345 | protected function resolveValue($value) |
||
357 | } |
||
358 |