1 | <?php |
||
9 | trait Criteriable |
||
10 | { |
||
11 | /** |
||
12 | * List of repository criteria. |
||
13 | * |
||
14 | * @var array |
||
15 | */ |
||
16 | protected $criteria = []; |
||
17 | |||
18 | /** |
||
19 | * List of default repository criteria. |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $defaultCriteria = []; |
||
24 | |||
25 | /** |
||
26 | * Skip criteria flag. |
||
27 | * If setted to true criteria will not be apply to the query. |
||
28 | * |
||
29 | * @var bool |
||
30 | */ |
||
31 | protected $skipCriteria = false; |
||
32 | |||
33 | /** |
||
34 | * Skip default criteria flag. |
||
35 | * If setted to true default criteria will not be added to the criteria list. |
||
36 | * |
||
37 | * @var bool |
||
38 | */ |
||
39 | protected $skipDefaultCriteria = false; |
||
40 | |||
41 | /** |
||
42 | * Return name for the criterion. |
||
43 | * If as criterion in parameter passed string we assume that is criterion class name. |
||
44 | * |
||
45 | * @param CriterionContract|Closure|string $criteria |
||
46 | * |
||
47 | * @return string |
||
48 | */ |
||
49 | public function getCriterionName($criteria) |
||
57 | |||
58 | /** |
||
59 | * Add criterion to the specific list. |
||
60 | * low-level implementation of adding criterion to the list. |
||
61 | * |
||
62 | * @param Closure|CriterionContract $criterion |
||
63 | * @param string $list |
||
64 | * |
||
65 | * @return $this |
||
66 | */ |
||
67 | protected function addCriterion($criterion, $list) |
||
82 | |||
83 | /** |
||
84 | * Push criterion to the criteria list. |
||
85 | * |
||
86 | * @param CriterionContract|Closure $criterion |
||
87 | * |
||
88 | * @return $this |
||
89 | */ |
||
90 | public function pushCriterion($criterion) |
||
96 | |||
97 | /** |
||
98 | * Remove provided criterion from criteria list. |
||
99 | * |
||
100 | * @param CriterionContract|Closure|string $criterion |
||
101 | * |
||
102 | * @return $this |
||
103 | */ |
||
104 | public function removeCriterion($criterion) |
||
110 | |||
111 | /** |
||
112 | * Remove provided criteria from criteria list. |
||
113 | * |
||
114 | * @param array $criteria |
||
115 | * |
||
116 | * @return RepositoryContract |
||
|
|||
117 | */ |
||
118 | public function removeCriteria(array $criteria) |
||
126 | |||
127 | /** |
||
128 | * Push array of criteria to the criteria list. |
||
129 | * |
||
130 | * @param array $criteria |
||
131 | * |
||
132 | * @return $this |
||
133 | */ |
||
134 | public function pushCriteria(array $criteria) |
||
142 | |||
143 | /** |
||
144 | * Flush criteria list. |
||
145 | * |
||
146 | * @return $this |
||
147 | */ |
||
148 | public function flushCriteria() |
||
153 | |||
154 | /** |
||
155 | * Set default criteria list. |
||
156 | * |
||
157 | * @param array $criteria |
||
158 | * |
||
159 | * @return $this |
||
160 | */ |
||
161 | public function setDefaultCriteria(array $criteria) |
||
169 | |||
170 | /** |
||
171 | * Return default criteria list. |
||
172 | * |
||
173 | * @return array |
||
174 | */ |
||
175 | public function getDefaultCriteria() |
||
179 | |||
180 | /** |
||
181 | * Return current list of criteria. |
||
182 | * |
||
183 | * @return array |
||
184 | */ |
||
185 | public function getCriteria() |
||
193 | |||
194 | /** |
||
195 | * Set skipCriteria flag. |
||
196 | * |
||
197 | * @param bool|true $flag |
||
198 | * |
||
199 | * @return $this |
||
200 | */ |
||
201 | public function skipCriteria($flag = true) |
||
207 | |||
208 | /** |
||
209 | * Set skipDefaultCriteria flag. |
||
210 | * |
||
211 | * @param bool|true $flag |
||
212 | * |
||
213 | * @return $this |
||
214 | */ |
||
215 | public function skipDefaultCriteria($flag = true) |
||
221 | |||
222 | /** |
||
223 | * Check if a given criterion name now in the criteria list. |
||
224 | * |
||
225 | * @param CriterionContract|Closure|string $criterion |
||
226 | * |
||
227 | * @return bool |
||
228 | */ |
||
229 | public function hasCriterion($criterion) |
||
233 | |||
234 | /** |
||
235 | * Return criterion object or closure from criteria list by name. |
||
236 | * |
||
237 | * @param $criterion |
||
238 | * |
||
239 | * @return CriterionContract|Closure|null |
||
240 | */ |
||
241 | public function getCriterion($criterion) |
||
247 | |||
248 | /** |
||
249 | * Apply criteria list to the given query. |
||
250 | * |
||
251 | * @param $query |
||
252 | * @param $repository |
||
253 | * |
||
254 | * @return mixed |
||
255 | */ |
||
256 | public function applyCriteria($query, $repository) |
||
268 | } |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.