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 | * Constructor. |
||
61 | * |
||
62 | * @param PdoConfig $config |
||
63 | */ |
||
64 | public function __construct(PdoConfig $config) |
||
79 | |||
80 | /** |
||
81 | * {@inheritdoc} |
||
82 | */ |
||
83 | public function save(ReadModelInterface $model, $table) |
||
100 | |||
101 | /** |
||
102 | * {@inheritdoc} |
||
103 | */ |
||
104 | public function remove($id, $table) |
||
109 | |||
110 | /** |
||
111 | * {@inheritdoc} |
||
112 | */ |
||
113 | public function findById($id, $table, $class) |
||
119 | |||
120 | /** |
||
121 | * {@inheritdoc} |
||
122 | */ |
||
123 | public function finder($table, $class) |
||
127 | |||
128 | /** |
||
129 | * Execute query without statement. |
||
130 | * |
||
131 | * @param string $sql |
||
132 | * @param array $values |
||
133 | */ |
||
134 | public function exec($sql, array $values = array()) |
||
152 | |||
153 | /** |
||
154 | * Execute query with statement. |
||
155 | * |
||
156 | * @param string $sql |
||
157 | * @param int $mode |
||
158 | * |
||
159 | * @return PDOStatement |
||
160 | */ |
||
161 | public function query($sql, $mode = PhpPdo::FETCH_ASSOC) |
||
169 | |||
170 | /** |
||
171 | * Begin transaction |
||
172 | */ |
||
173 | public function beginTransaction() |
||
181 | |||
182 | /** |
||
183 | * Rollback transaction |
||
184 | */ |
||
185 | public function rollback() |
||
190 | |||
191 | /** |
||
192 | * Commit transaction. |
||
193 | */ |
||
194 | public function commit() |
||
201 | |||
202 | /** |
||
203 | * Compute fields to expressions. |
||
204 | * |
||
205 | * @param array $fields |
||
206 | * @param PdoFinder $finder |
||
207 | * |
||
208 | * @return PdoCompositeExpression |
||
209 | */ |
||
210 | protected function computeFieldsExpression(array $fields, PdoFinder $finder) |
||
219 | |||
220 | /** |
||
221 | * Normalize value. |
||
222 | * |
||
223 | * @param array $values |
||
224 | * |
||
225 | * @return array |
||
226 | */ |
||
227 | protected function normalize(array $values) |
||
248 | |||
249 | /** |
||
250 | * Build query update. |
||
251 | * |
||
252 | * @param array $values |
||
253 | * @param array $conditions |
||
254 | * @param string $table |
||
255 | * |
||
256 | * @return string |
||
257 | */ |
||
258 | protected function buildUpdateQuery(array $values, array $conditions, $table) |
||
268 | |||
269 | /** |
||
270 | * Build insert query. |
||
271 | * |
||
272 | * @param array $values |
||
273 | * @param string $table |
||
274 | * |
||
275 | * @return string |
||
276 | */ |
||
277 | public function buildInsertQuery(array $values, $table) |
||
286 | |||
287 | /** |
||
288 | * Build data sets. |
||
289 | * |
||
290 | * @param array $parts |
||
291 | * |
||
292 | * @return array |
||
293 | */ |
||
294 | protected function buildDataSets(array $parts) |
||
303 | |||
304 | /** |
||
305 | * Quote field. |
||
306 | * |
||
307 | * @param string $field |
||
308 | * |
||
309 | * @return string |
||
310 | */ |
||
311 | protected function quote($field) |
||
315 | |||
316 | /** |
||
317 | * @param mixed $value |
||
318 | * |
||
319 | * @return mixed|null|string |
||
320 | */ |
||
321 | protected function resolveValue($value) |
||
333 | } |
||
334 |