1 | <?php |
||
28 | abstract class Repository implements RepositoryInterface |
||
29 | { |
||
30 | use Filterable, Sortable; |
||
31 | |||
32 | /** |
||
33 | * Contains Laravel Application instance. |
||
34 | * |
||
35 | * @var Application |
||
36 | */ |
||
37 | protected $app; |
||
38 | |||
39 | /** |
||
40 | * Contains Eloquent model instance. |
||
41 | * |
||
42 | * @var Eloquent |
||
43 | */ |
||
44 | public $model; |
||
45 | |||
46 | /** |
||
47 | * Contains relations to eager load. |
||
48 | * |
||
49 | * @var array |
||
50 | */ |
||
51 | public $with = []; |
||
52 | |||
53 | /** |
||
54 | * Contains time of caching. |
||
55 | * |
||
56 | * @var int |
||
57 | */ |
||
58 | public $lifetime; |
||
59 | |||
60 | /** |
||
61 | * Contains transformer instance. |
||
62 | * |
||
63 | * @var string |
||
64 | */ |
||
65 | public $transformer; |
||
66 | |||
67 | /** |
||
68 | * Contains repository mediator instance. |
||
69 | * |
||
70 | * @var RepositoryMediator |
||
71 | */ |
||
72 | public $mediator; |
||
73 | |||
74 | /** |
||
75 | * Create a new RepositoryInterface instance. |
||
76 | * |
||
77 | * @param Application $app |
||
78 | */ |
||
79 | 120 | public function __construct(Application $app) |
|
84 | |||
85 | /** |
||
86 | * Create a new RepositoryInterface instance. |
||
87 | * |
||
88 | * @return static |
||
89 | */ |
||
90 | 8 | public static function instance() |
|
94 | |||
95 | /** |
||
96 | * Call an action on mediator. |
||
97 | * |
||
98 | * @param array $parameters |
||
99 | * |
||
100 | * @return mixed |
||
101 | */ |
||
102 | 86 | public function mediator(array $parameters) |
|
112 | |||
113 | /** |
||
114 | * Add criteria to repository query or return criteria service. |
||
115 | * |
||
116 | * @param CriteriaInterface|null $criteria |
||
117 | * |
||
118 | * @throws InvalidCriteria |
||
119 | * |
||
120 | * @return CriteriaService|$this |
||
121 | */ |
||
122 | 8 | public function criteria($criteria = null) |
|
136 | |||
137 | /** |
||
138 | * Return fully qualified model class name. |
||
139 | * |
||
140 | * @return string |
||
141 | */ |
||
142 | abstract public function takeModel(); |
||
143 | |||
144 | /** |
||
145 | * Return instance of Eloquent model. |
||
146 | * |
||
147 | * @throws InvalidRepositoryModel |
||
148 | * |
||
149 | * @return Eloquent |
||
150 | */ |
||
151 | 120 | public function makeModel() |
|
159 | |||
160 | /** |
||
161 | * Return instance of query builder for Eloquent model. |
||
162 | * |
||
163 | * @return \Illuminate\Database\Eloquent\Builder |
||
164 | */ |
||
165 | 84 | public function makeQuery() |
|
175 | |||
176 | /** |
||
177 | * Adds relation to eager loads. |
||
178 | * |
||
179 | * @param string|string[] $relation |
||
180 | * |
||
181 | * @return static |
||
182 | */ |
||
183 | 4 | public function with($relation) |
|
193 | |||
194 | /** |
||
195 | * Sets transformer to current repository instance. |
||
196 | * |
||
197 | * @param string $transformer |
||
198 | * |
||
199 | * @throws InvalidTransformer |
||
200 | * |
||
201 | * @return static |
||
202 | */ |
||
203 | 4 | public function setTransformer($transformer) |
|
213 | |||
214 | /** |
||
215 | * Get all of the models from the database. |
||
216 | * |
||
217 | * @param string[] $columns |
||
218 | * |
||
219 | * @return Collection |
||
220 | */ |
||
221 | 12 | public function all(array $columns = ['*']) |
|
225 | |||
226 | /** |
||
227 | * Create a new basic where query clause on model. |
||
228 | * |
||
229 | * @param string|array $column |
||
230 | * @param string $operator |
||
231 | * @param mixed $value |
||
232 | * @param string $boolean |
||
233 | * @param string[] $columns |
||
234 | * |
||
235 | * @return mixed |
||
236 | */ |
||
237 | 8 | public function where($column, $operator = '=', $value = null, $boolean = 'and', array $columns = ['*']) |
|
241 | |||
242 | /** |
||
243 | * Paginate the given query. |
||
244 | * |
||
245 | * @param int $perPage |
||
246 | * @param string[] $columns |
||
247 | * |
||
248 | * @return LengthAwarePaginator |
||
249 | */ |
||
250 | 8 | public function paginate($perPage = 15, array $columns = ['*']) |
|
254 | |||
255 | /** |
||
256 | * Save a new model and return the instance. |
||
257 | * |
||
258 | * @param array $attributes |
||
259 | * |
||
260 | * @return Eloquent |
||
261 | */ |
||
262 | 6 | public function create(array $attributes = []) |
|
266 | |||
267 | /** |
||
268 | * Save or update the model in the database. |
||
269 | * |
||
270 | * @param mixed $identifier |
||
271 | * @param array $attributes |
||
272 | * |
||
273 | * @return Eloquent |
||
274 | */ |
||
275 | 6 | public function update($identifier, array $attributes = []) |
|
279 | |||
280 | /** |
||
281 | * Delete the model from the database. |
||
282 | * |
||
283 | * @param int $identifier |
||
284 | * |
||
285 | * @return bool|null |
||
286 | */ |
||
287 | 6 | public function delete($identifier) |
|
291 | |||
292 | /** |
||
293 | * Find a model by its primary key. |
||
294 | * |
||
295 | * @param int $identifier |
||
296 | * @param string[] $columns |
||
297 | * |
||
298 | * @return Eloquent |
||
299 | */ |
||
300 | 28 | public function find($identifier, array $columns = ['*']) |
|
304 | |||
305 | /** |
||
306 | * Find a model by its specified column and value. |
||
307 | * |
||
308 | * @param mixed $column |
||
309 | * @param mixed $value |
||
310 | * @param string[] $columns |
||
311 | * |
||
312 | * @return Eloquent |
||
313 | */ |
||
314 | 8 | public function findBy($column, $value, array $columns = ['*']) |
|
318 | |||
319 | /** |
||
320 | * Find a model by its specified columns and values. |
||
321 | * |
||
322 | * @param array $wheres |
||
323 | * @param string[] $columns |
||
324 | * |
||
325 | * @return Eloquent |
||
326 | */ |
||
327 | 8 | public function findWhere(array $wheres, array $columns = ['*']) |
|
331 | |||
332 | /** |
||
333 | * Returns total count of whole collection. |
||
334 | * |
||
335 | * @return int |
||
336 | */ |
||
337 | 4 | public function count() |
|
341 | |||
342 | /** |
||
343 | * Fetch collection ordered and filtrated by specified columns for specified page. |
||
344 | * |
||
345 | * @param int $page |
||
346 | * @param int $perPage |
||
347 | * @param array $filter |
||
348 | * @param array $sort |
||
349 | * @param array $columns |
||
350 | * |
||
351 | * @return LengthAwarePaginator |
||
352 | */ |
||
353 | 12 | public function fetch($page = 1, $perPage = 15, array $columns = ['*'], array $filter = [], array $sort = []) |
|
357 | |||
358 | /** |
||
359 | * @param int $page |
||
360 | * @param int $perPage |
||
361 | * @param array $columns |
||
362 | * @param array $filter |
||
363 | * @param array $sort |
||
364 | * |
||
365 | * @return Collection |
||
366 | */ |
||
367 | 4 | public function simpleFetch($page = 1, $perPage = 15, array $columns = ['*'], array $filter = [], array $sort = []) |
|
371 | |||
372 | /** |
||
373 | * Determinate if repository should be cached. |
||
374 | * |
||
375 | * @return bool |
||
376 | */ |
||
377 | 86 | protected function shouldCache() |
|
385 | |||
386 | /** |
||
387 | * Dynamicaly calls method on model instance. |
||
388 | * |
||
389 | * @param string $method |
||
390 | * @param array $parameters |
||
391 | * |
||
392 | * @throws InvalidRepositoryModel |
||
393 | * |
||
394 | * @return mixed |
||
395 | */ |
||
396 | 12 | public function __call($method, $parameters) |
|
404 | } |
||
405 |