1 | <?php |
||
24 | abstract class BaseRepository implements RepositoryContract, CacheableContract |
||
25 | { |
||
26 | use Cacheable; |
||
27 | |||
28 | /** |
||
29 | * The IoC container instance. |
||
30 | * |
||
31 | * @var \Illuminate\Contracts\Container\Container |
||
32 | */ |
||
33 | protected $container; |
||
34 | |||
35 | /** |
||
36 | * The repository identifier. |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $repositoryId; |
||
41 | |||
42 | /** |
||
43 | * The repository model. |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $model; |
||
48 | |||
49 | /** |
||
50 | * The relations to eager load on query execution. |
||
51 | * |
||
52 | * @var array |
||
53 | */ |
||
54 | protected $relations = []; |
||
55 | |||
56 | /** |
||
57 | * The query where clauses. |
||
58 | * |
||
59 | * @var array |
||
60 | */ |
||
61 | protected $where = []; |
||
62 | |||
63 | /** |
||
64 | * The query whereIn clauses. |
||
65 | * |
||
66 | * @var array |
||
67 | */ |
||
68 | protected $whereIn = []; |
||
69 | |||
70 | /** |
||
71 | * The query whereNotIn clauses. |
||
72 | * |
||
73 | * @var array |
||
74 | */ |
||
75 | protected $whereNotIn = []; |
||
76 | |||
77 | /** |
||
78 | * The query whereHas clauses. |
||
79 | * |
||
80 | * @var array |
||
81 | */ |
||
82 | protected $whereHas = []; |
||
83 | |||
84 | /** |
||
85 | * The "offset" value of the query. |
||
86 | * |
||
87 | * @var int |
||
88 | */ |
||
89 | protected $offset; |
||
90 | |||
91 | /** |
||
92 | * The "limit" value of the query. |
||
93 | * |
||
94 | * @var int |
||
95 | */ |
||
96 | protected $limit; |
||
97 | |||
98 | /** |
||
99 | * The column to order results by. |
||
100 | * |
||
101 | * @var array |
||
102 | */ |
||
103 | protected $orderBy = []; |
||
104 | |||
105 | /** |
||
106 | * Execute given callback and return the result. |
||
107 | * |
||
108 | * @param string $class |
||
109 | * @param string $method |
||
110 | * @param array $args |
||
111 | * @param \Closure $closure |
||
112 | * |
||
113 | * @return mixed |
||
114 | */ |
||
115 | protected function executeCallback($class, $method, $args, Closure $closure) |
||
132 | |||
133 | /** |
||
134 | * Reset repository to it's defaults. |
||
135 | * |
||
136 | * @return $this |
||
137 | */ |
||
138 | protected function resetRepository() |
||
151 | |||
152 | /** |
||
153 | * Prepare query. |
||
154 | * |
||
155 | * @param object $model |
||
156 | * |
||
157 | * @return object |
||
158 | */ |
||
159 | protected function prepareQuery($model) |
||
213 | |||
214 | /** |
||
215 | * Set the IoC container instance. |
||
216 | * |
||
217 | * @param \Illuminate\Contracts\Container\Container $container |
||
218 | * |
||
219 | * @return $this |
||
220 | */ |
||
221 | public function setContainer(Container $container) |
||
227 | |||
228 | /** |
||
229 | * Get the IoC container instance or any of it's services. |
||
230 | * |
||
231 | * @param string|null $service |
||
232 | * |
||
233 | * @return object |
||
234 | */ |
||
235 | public function getContainer($service = null) |
||
239 | |||
240 | /** |
||
241 | * Set the repository identifier. |
||
242 | * |
||
243 | * @param string $repositoryId |
||
244 | * |
||
245 | * @return $this |
||
246 | */ |
||
247 | public function setRepositoryId($repositoryId) |
||
253 | |||
254 | /** |
||
255 | * Get the repository identifier. |
||
256 | * |
||
257 | * @return string |
||
258 | */ |
||
259 | public function getRepositoryId() |
||
263 | |||
264 | /** |
||
265 | * Set the repository model. |
||
266 | * |
||
267 | * @param string $model |
||
268 | * |
||
269 | * @return $this |
||
270 | */ |
||
271 | public function setModel($model) |
||
277 | |||
278 | /** |
||
279 | * Get the repository model. |
||
280 | * |
||
281 | * @return string |
||
282 | */ |
||
283 | public function getModel() |
||
289 | |||
290 | /** |
||
291 | * Set the relationships that should be eager loaded. |
||
292 | * |
||
293 | * @param array $relations |
||
294 | * |
||
295 | * @return $this |
||
296 | */ |
||
297 | public function with(array $relations) |
||
303 | |||
304 | /** |
||
305 | * Add a basic where clause to the query. |
||
306 | * |
||
307 | * @param string $attribute |
||
308 | * @param string $operator |
||
309 | * @param mixed $value |
||
310 | * @param string $boolean |
||
311 | * |
||
312 | * @return $this |
||
313 | */ |
||
314 | public function where($attribute, $operator = null, $value = null, $boolean = 'and') |
||
321 | |||
322 | /** |
||
323 | * Add a "where in" clause to the query. |
||
324 | * |
||
325 | * @param string $attribute |
||
326 | * @param mixed $values |
||
327 | * @param string $boolean |
||
328 | * @param bool $not |
||
329 | * |
||
330 | * @return $this |
||
331 | */ |
||
332 | public function whereIn($attribute, $values, $boolean = 'and', $not = false) |
||
339 | |||
340 | /** |
||
341 | * Add a "where not in" clause to the query. |
||
342 | * |
||
343 | * @param string $attribute |
||
344 | * @param mixed $values |
||
345 | * @param string $boolean |
||
346 | * |
||
347 | * @return $this |
||
348 | */ |
||
349 | public function whereNotIn($attribute, $values, $boolean = 'and') |
||
356 | |||
357 | /** |
||
358 | * Add a relationship count / exists condition to the query with where clauses. |
||
359 | * |
||
360 | * @param string $relation |
||
361 | * @param \Closure $callback |
||
362 | * @param string $operator |
||
363 | * @param int $count |
||
364 | * |
||
365 | * @return $this |
||
366 | */ |
||
367 | public function whereHas($relation, \Closure $callback, $operator = '>=', $count = 1) |
||
373 | |||
374 | /** |
||
375 | * Set the "offset" value of the query. |
||
376 | * |
||
377 | * @param int $offset |
||
378 | * |
||
379 | * @return $this |
||
380 | */ |
||
381 | public function offset($offset) |
||
387 | |||
388 | /** |
||
389 | * Set the "limit" value of the query. |
||
390 | * |
||
391 | * @param int $limit |
||
392 | * |
||
393 | * @return $this |
||
394 | */ |
||
395 | public function limit($limit) |
||
401 | |||
402 | /** |
||
403 | * Add an "order by" clause to the query. |
||
404 | * |
||
405 | * @param string $attribute |
||
406 | * @param string $direction |
||
407 | * |
||
408 | * @return $this |
||
409 | */ |
||
410 | public function orderBy($attribute, $direction = 'asc') |
||
416 | |||
417 | /** |
||
418 | * Dynamically pass missing static methods to the model. |
||
419 | * |
||
420 | * @param $method |
||
421 | * @param $parameters |
||
422 | * |
||
423 | * @return mixed |
||
424 | */ |
||
425 | public static function __callStatic($method, $parameters) |
||
429 | |||
430 | /** |
||
431 | * Dynamically pass missing methods to the model. |
||
432 | * |
||
433 | * @param string $method |
||
434 | * @param array $parameters |
||
435 | * |
||
436 | * @return mixed |
||
437 | */ |
||
438 | public function __call($method, $parameters) |
||
442 | } |
||
443 |