1 | <?php |
||
20 | class RepositoryMediator |
||
21 | { |
||
22 | /** |
||
23 | * Contains Laravel Application instance. |
||
24 | * |
||
25 | * @var Application |
||
26 | */ |
||
27 | protected $app; |
||
28 | |||
29 | /** |
||
30 | * Contains a repository instance. |
||
31 | * |
||
32 | * @var Repository |
||
33 | */ |
||
34 | protected $repository; |
||
35 | |||
36 | /** |
||
37 | * Contains a database service. |
||
38 | * |
||
39 | * @var DatabaseService |
||
40 | */ |
||
41 | protected $database; |
||
42 | |||
43 | /** |
||
44 | * Contains an cache service. |
||
45 | * |
||
46 | * @var CacheService |
||
47 | */ |
||
48 | protected $cache; |
||
49 | |||
50 | /** |
||
51 | * Contains a transform service. |
||
52 | * |
||
53 | * @var TransformService |
||
54 | */ |
||
55 | protected $transform; |
||
56 | |||
57 | /** |
||
58 | * Contains an Criteria service. |
||
59 | * |
||
60 | * @var CriteriaService |
||
61 | */ |
||
62 | protected $criteria; |
||
63 | |||
64 | /** |
||
65 | * Create a new Repositry Mediator instance. |
||
66 | * |
||
67 | * @param Application $app |
||
68 | * @param Repository $repository |
||
69 | */ |
||
70 | 120 | public function __construct(Application $app, Repository $repository) |
|
79 | |||
80 | /** |
||
81 | * Retrieve data from cache storage, or execute method |
||
82 | * on database and store result then return it. |
||
83 | * |
||
84 | * @param string $caller |
||
85 | * @param array $parameters |
||
86 | * |
||
87 | * @return mixed |
||
88 | */ |
||
89 | 20 | public function cache($caller, array $parameters = []) |
|
93 | |||
94 | /** |
||
95 | * Execute method with parameters on database service. |
||
96 | * |
||
97 | * @param string $caller |
||
98 | * @param array $parameters |
||
99 | * |
||
100 | * @return mixed |
||
101 | */ |
||
102 | 86 | public function database($caller, array $parameters = []) |
|
106 | |||
107 | /** |
||
108 | * Execute transform method on specified transformer. |
||
109 | * |
||
110 | * @param mixed $collection |
||
111 | * |
||
112 | * @return Collection |
||
113 | */ |
||
114 | 68 | public function transform($collection) |
|
129 | |||
130 | /** |
||
131 | * Execute transform method on paginator items with specified transformer. |
||
132 | * |
||
133 | * @param LengthAwarePaginator $paginator |
||
134 | * |
||
135 | * @return LengthAwarePaginator |
||
136 | */ |
||
137 | 20 | public function transformPaginator(LengthAwarePaginator $paginator) |
|
147 | |||
148 | /** |
||
149 | * Determinate if repository has a transformer. |
||
150 | * |
||
151 | * @return bool |
||
152 | */ |
||
153 | 82 | public function hasTransformer() |
|
157 | |||
158 | /** |
||
159 | * Returns criteria service on model query. |
||
160 | * |
||
161 | * @return CriteriaService |
||
162 | */ |
||
163 | 24 | public function criteria() |
|
167 | |||
168 | /** |
||
169 | * Determinate if repository has an criteria. |
||
170 | * |
||
171 | * @return bool |
||
172 | */ |
||
173 | 84 | public function hasCriteria() |
|
177 | } |
||
178 |