1 | <?php |
||
20 | abstract class AbstractRepository implements ContractInterface |
||
21 | { |
||
22 | protected $with = []; |
||
23 | /** |
||
24 | * @var App |
||
25 | */ |
||
26 | protected $app; |
||
27 | |||
28 | /** @var string */ |
||
29 | protected $order = null; |
||
30 | |||
31 | protected $direction = 'desc'; |
||
32 | /** |
||
33 | * @var Entity |
||
34 | */ |
||
35 | protected $model; |
||
36 | /** |
||
37 | * @var boolean |
||
38 | */ |
||
39 | private $trash = false; |
||
40 | /** |
||
41 | * @var boolean |
||
42 | */ |
||
43 | private $withTrash = false; |
||
44 | |||
45 | /** |
||
46 | * @param App $app |
||
47 | */ |
||
48 | public function __construct(App $app) |
||
53 | |||
54 | protected function makeModel() |
||
58 | |||
59 | /** |
||
60 | * @return string |
||
61 | */ |
||
62 | abstract protected function getModelClass(): string; |
||
63 | |||
64 | /** |
||
65 | * @param int $limit |
||
66 | * @param array $criteria |
||
67 | * |
||
68 | * @return Paginator |
||
69 | */ |
||
70 | public function simplePaginate($limit = 10, $criteria = []) |
||
74 | |||
75 | /** |
||
76 | * @param array $criteria |
||
77 | * @return Entity |
||
78 | */ |
||
79 | public function filter($criteria = []) |
||
106 | |||
107 | /** |
||
108 | * prepare order for query |
||
109 | * |
||
110 | * @param array $criteria |
||
111 | * |
||
112 | * @return array |
||
113 | */ |
||
114 | private function order($criteria=[]){ |
||
129 | |||
130 | /** |
||
131 | * @param int $limit |
||
132 | * @param array $criteria |
||
133 | * |
||
134 | * @return LengthAwarePaginator |
||
135 | */ |
||
136 | public function paginate($limit = 10, $criteria = []) |
||
140 | |||
141 | /** |
||
142 | * @param array $criteria |
||
143 | * |
||
144 | * @return Builder[]|\Illuminate\Database\Eloquent\Collection |
||
145 | */ |
||
146 | public function get($criteria = []) |
||
150 | |||
151 | /** |
||
152 | * @param $entityId |
||
153 | * @param array $attributes |
||
154 | * |
||
155 | * @return bool |
||
156 | */ |
||
157 | public function update($entityId = 0, $attributes = []) |
||
167 | |||
168 | /** |
||
169 | * @param $entityId |
||
170 | * |
||
171 | * @throws \Exception |
||
172 | * |
||
173 | * @return bool |
||
174 | */ |
||
175 | public function delete($entityId = 0) |
||
181 | |||
182 | /** |
||
183 | * @param array $attributes |
||
184 | * |
||
185 | * @return bool |
||
186 | */ |
||
187 | public function insert($attributes = []) |
||
191 | |||
192 | |||
193 | /** |
||
194 | * @param array $columns |
||
195 | * |
||
196 | * @return mixed |
||
197 | */ |
||
198 | public function all($columns = ['*']) |
||
202 | |||
203 | /** |
||
204 | * @param string $name |
||
205 | * @param string $entityId |
||
206 | * @param array $criteria |
||
207 | * |
||
208 | * @return array |
||
209 | */ |
||
210 | public function pluck($name = 'name', $entityId = 'id', $criteria = []) |
||
214 | |||
215 | /** |
||
216 | * @param $entityId |
||
217 | * @param array $columns |
||
218 | * |
||
219 | * @return Entity |
||
220 | */ |
||
221 | public function find($entityId = 0, $columns = ['*']) |
||
225 | |||
226 | /** |
||
227 | * @param array $filter |
||
228 | * @param array $columns |
||
229 | * |
||
230 | * @return Entity |
||
231 | */ |
||
232 | public function first($filter = [], $columns = ['*']) |
||
236 | |||
237 | /** |
||
238 | * @param $haystack |
||
239 | * @param $needle |
||
240 | * |
||
241 | * @return Entity[]|\Illuminate\Database\Eloquent\Collection |
||
242 | */ |
||
243 | public function search($haystack, $needle) |
||
247 | |||
248 | |||
249 | /** |
||
250 | * @param $criteria |
||
251 | * @param array $columns |
||
252 | * |
||
253 | * @return Entity |
||
254 | */ |
||
255 | public function findBy($criteria = [], $columns = ['*']) |
||
259 | |||
260 | /** |
||
261 | * @param array $attributes |
||
262 | * |
||
263 | * @return Entity|\Illuminate\Database\Eloquent\Model |
||
264 | */ |
||
265 | public function create($attributes = []) |
||
269 | |||
270 | /** |
||
271 | * @param array $attributes |
||
272 | * |
||
273 | * @return Entity|\Illuminate\Database\Eloquent\Model |
||
274 | */ |
||
275 | public function createOrUpdate($attributes = []) |
||
279 | |||
280 | /** |
||
281 | * @param array $data |
||
282 | * |
||
283 | * @return \Illuminate\Database\Eloquent\Model |
||
284 | */ |
||
285 | public function createOrFirst($data = []) |
||
289 | |||
290 | /** |
||
291 | * Get entity name |
||
292 | * |
||
293 | * @return string |
||
294 | */ |
||
295 | public function entityName() |
||
299 | |||
300 | /** |
||
301 | * @param int $entityId |
||
302 | * |
||
303 | * @return bool |
||
304 | */ |
||
305 | public function restore($entityId = 0) |
||
317 | |||
318 | /** |
||
319 | * @param int $entityId |
||
320 | * |
||
321 | * @return bool |
||
322 | */ |
||
323 | public function forceDelete($entityId = 0) |
||
335 | |||
336 | /** |
||
337 | * @return void |
||
338 | */ |
||
339 | public function trash() |
||
344 | |||
345 | /** |
||
346 | * @return void |
||
347 | */ |
||
348 | public function withTrash() |
||
353 | } |
||
354 |