1 | <?php |
||
9 | class Repository |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * @var Mapper |
||
14 | */ |
||
15 | protected $mapper; |
||
16 | |||
17 | /** |
||
18 | * @var DbDriverInterface |
||
19 | */ |
||
20 | protected $dbDriver = null; |
||
21 | |||
22 | /** |
||
23 | * @var \Closure |
||
24 | */ |
||
25 | protected $beforeUpdate = null; |
||
26 | 21 | ||
27 | /** |
||
28 | 21 | * @var \Closure |
|
29 | 21 | */ |
|
30 | 21 | protected $beforeInsert = null; |
|
31 | |||
32 | /** |
||
33 | * Repository constructor. |
||
34 | * @param DbDriverInterface $dbDataset |
||
35 | 9 | * @param Mapper $mapper |
|
36 | */ |
||
37 | 9 | public function __construct(DbDriverInterface $dbDataset, Mapper $mapper) |
|
48 | |||
49 | /** |
||
50 | * @return Mapper |
||
51 | */ |
||
52 | 14 | public function getMapper() |
|
56 | 14 | ||
57 | 14 | /** |
|
58 | * @return DbDriverInterface |
||
59 | */ |
||
60 | 3 | protected function getDbDriver() |
|
64 | |||
65 | /** |
||
66 | * @param array|string $pkId |
||
67 | * @return mixed|null |
||
68 | 2 | */ |
|
69 | public function get($pkId) |
||
79 | |||
80 | /** |
||
81 | * @param array $pkId |
||
82 | * @return mixed|null |
||
83 | 3 | * @throws \Exception |
|
84 | */ |
||
85 | 3 | public function delete($pkId) |
|
94 | |||
95 | /** |
||
96 | * @param $updatable |
||
97 | * @return bool |
||
98 | */ |
||
99 | 14 | public function deleteByQuery(Updatable $updatable) |
|
108 | |||
109 | 14 | /** |
|
110 | * @param string $filter |
||
111 | * @param array $params |
||
112 | * @param bool $forUpdate |
||
113 | * @return array |
||
114 | */ |
||
115 | public function getByFilter($filter, array $params, $forUpdate = false) |
||
127 | 21 | ||
128 | 21 | public function getScalar(Query $query) |
|
136 | 2 | ||
137 | 2 | /** |
|
138 | 21 | * @param Query $query |
|
139 | 21 | * @param Mapper[] $mapper |
|
140 | * @return array |
||
141 | 21 | */ |
|
142 | 10 | public function getByQuery(Query $query, array $mapper = []) |
|
184 | 3 | ||
185 | 8 | /** |
|
186 | * @param mixed $instance |
||
187 | * @return mixed |
||
188 | 8 | * @throws \ByJG\MicroOrm\Exception\OrmBeforeInvalidException |
|
189 | 8 | * @throws \ByJG\MicroOrm\Exception\OrmInvalidFieldsException |
|
190 | 8 | * @throws \Exception |
|
191 | */ |
||
192 | public function save($instance) |
||
251 | |||
252 | 3 | /** |
|
253 | * @param \ByJG\MicroOrm\Updatable $updatable |
||
254 | 3 | * @param array $params |
|
255 | 3 | * @return int |
|
256 | * @throws \ByJG\MicroOrm\Exception\OrmInvalidFieldsException |
||
257 | 3 | */ |
|
258 | protected function insert(Updatable $updatable, array $params) |
||
267 | |||
268 | /** |
||
269 | * @param \ByJG\MicroOrm\Updatable $updatable |
||
270 | * @param array $params |
||
271 | * @return int |
||
272 | * @throws \ByJG\MicroOrm\Exception\OrmInvalidFieldsException |
||
273 | */ |
||
274 | protected function insertWithAutoinc(Updatable $updatable, array $params) |
||
280 | |||
281 | /** |
||
282 | * @param \ByJG\MicroOrm\Updatable $updatable |
||
283 | * @param array $params |
||
284 | * @param $keyGen |
||
285 | * @return mixed |
||
286 | * @throws \ByJG\MicroOrm\Exception\OrmInvalidFieldsException |
||
287 | */ |
||
288 | protected function insertWithKeyGen(Updatable $updatable, array $params, $keyGen) |
||
295 | |||
296 | /** |
||
297 | * @param \ByJG\MicroOrm\Updatable $updatable |
||
298 | * @param array $params |
||
299 | */ |
||
300 | protected function update(Updatable $updatable, array $params) |
||
309 | |||
310 | public function setBeforeUpdate(\Closure $closure) |
||
314 | |||
315 | public function setBeforeInsert(\Closure $closure) |
||
319 | } |
||
320 |