1 | <?php |
||
9 | trait Criteriable |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * List of repository criteria. |
||
14 | * |
||
15 | * @var array |
||
16 | */ |
||
17 | protected $criteria = []; |
||
18 | |||
19 | /** |
||
20 | * List of default repository criteria. |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $defaultCriteria = []; |
||
25 | |||
26 | /** |
||
27 | * Skip criteria flag. |
||
28 | * If setted to true criteria will not be apply to the query. |
||
29 | * |
||
30 | * @var bool |
||
31 | */ |
||
32 | protected $skipCriteria = false; |
||
33 | |||
34 | /** |
||
35 | * Skip default criteria flag. |
||
36 | * If setted to true default criteria will not be added to the criteria list. |
||
37 | * |
||
38 | * @var bool |
||
39 | */ |
||
40 | protected $skipDefaultCriteria = false; |
||
41 | |||
42 | /** |
||
43 | * Return name for the criterion. |
||
44 | * If as criterion in parameter passed string we assume that is criterion class name. |
||
45 | * |
||
46 | * @param CriterionContract|Closure|String $criteria |
||
47 | * |
||
48 | * @return string |
||
49 | */ |
||
50 | public function getCriterionName($criteria) |
||
58 | |||
59 | /** |
||
60 | * Add criterion to the specific list. |
||
61 | * low-level implementation of adding criterion to the list |
||
62 | * |
||
63 | * @param Closure|CriterionContract $criterion |
||
64 | * @param string $list |
||
65 | * |
||
66 | * @return $this |
||
67 | */ |
||
68 | protected function addCriterion($criterion, $list) |
||
83 | |||
84 | /** |
||
85 | * Push criterion to the criteria list. |
||
86 | * |
||
87 | * @param CriterionContract|Closure $criterion |
||
88 | * |
||
89 | * @return $this |
||
90 | */ |
||
91 | 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) |
||
109 | |||
110 | /** |
||
111 | * Remove provided criteria from criteria list. |
||
112 | * |
||
113 | * @param array $criteria |
||
114 | * |
||
115 | * @return RepositoryContract |
||
|
|||
116 | */ |
||
117 | public function removeCriteria(array $criteria) |
||
125 | |||
126 | /** |
||
127 | * Push array of criteria to the criteria list. |
||
128 | * |
||
129 | * @param array $criteria |
||
130 | * |
||
131 | * @return $this |
||
132 | */ |
||
133 | public function pushCriteria(array $criteria) |
||
141 | |||
142 | /** |
||
143 | * Flush criteria list |
||
144 | * |
||
145 | * @return $this |
||
146 | */ |
||
147 | public function flushCriteria() |
||
152 | |||
153 | /** |
||
154 | * Set default criteria list. |
||
155 | * |
||
156 | * @param array $criteria |
||
157 | * |
||
158 | * @return $this |
||
159 | */ |
||
160 | public function setDefaultCriteria(array $criteria) |
||
168 | |||
169 | /** |
||
170 | * Return default criteria list. |
||
171 | * |
||
172 | * @return array |
||
173 | */ |
||
174 | public function getDefaultCriteria() |
||
178 | |||
179 | /** |
||
180 | * Return current list of criteria. |
||
181 | * |
||
182 | * @return array |
||
183 | */ |
||
184 | public function getCriteria() |
||
192 | |||
193 | /** |
||
194 | * Set skipCriteria flag. |
||
195 | * |
||
196 | * @param bool|true $flag |
||
197 | * |
||
198 | * @return $this |
||
199 | */ |
||
200 | public function skipCriteria($flag = true) |
||
205 | |||
206 | /** |
||
207 | * Set skipDefaultCriteria flag. |
||
208 | * |
||
209 | * @param bool|true $flag |
||
210 | * |
||
211 | * @return $this |
||
212 | */ |
||
213 | public function skipDefaultCriteria($flag = true) |
||
218 | |||
219 | /** |
||
220 | * Check if a given criterion name now in the criteria list. |
||
221 | * |
||
222 | * @param CriterionContract|Closure|string $criterion |
||
223 | * |
||
224 | * @return bool |
||
225 | */ |
||
226 | public function hasCriterion($criterion) |
||
230 | |||
231 | /** |
||
232 | * Return criterion object or closure from criteria list by name. |
||
233 | * |
||
234 | * @param $criterion |
||
235 | * @return CriterionContract|Closure|null |
||
236 | */ |
||
237 | public function getCriterion($criterion) |
||
243 | |||
244 | /** |
||
245 | * Apply criteria list to the given query. |
||
246 | * |
||
247 | * @param $query |
||
248 | * @param $repository |
||
249 | * |
||
250 | * @return mixed |
||
251 | */ |
||
252 | public function applyCriteria($query, $repository) |
||
264 | } |
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.