1 | <?php |
||
8 | trait Criteriable |
||
9 | { |
||
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 | * @return string |
||
47 | */ |
||
48 | public function getCriterionName($criteria) |
||
56 | |||
57 | /** |
||
58 | * Add criterion to the specific list. |
||
59 | * low-level implementation of adding criterion to the list |
||
60 | * |
||
61 | * @param Closure|CriterionContract $criterion |
||
62 | * @param string $list |
||
63 | * |
||
64 | * @return $this |
||
65 | */ |
||
66 | protected function addCriterion($criterion, $list) |
||
81 | |||
82 | /** |
||
83 | * Push criterion to the criteria list. |
||
84 | * |
||
85 | * @param CriterionContract|Closure $criterion |
||
86 | * @return $this |
||
87 | */ |
||
88 | public function pushCriterion($criterion) |
||
93 | |||
94 | /** |
||
95 | * Remove provided criterion from criteria list |
||
96 | * |
||
97 | * @param CriterionContract|Closure|string $criterion |
||
98 | * @return $this |
||
99 | */ |
||
100 | public function removeCriterion($criterion) |
||
105 | |||
106 | /** |
||
107 | * Remove provided criteria from criteria list |
||
108 | * |
||
109 | * @param array $criteria |
||
110 | * @return RepositoryContract |
||
|
|||
111 | */ |
||
112 | public function removeCriteria(array $criteria) |
||
120 | |||
121 | /** |
||
122 | * Flush criteria list |
||
123 | * |
||
124 | * @return $this |
||
125 | */ |
||
126 | public function pushCriteria(array $criteria) |
||
134 | |||
135 | /** |
||
136 | * Flush criteria list |
||
137 | * |
||
138 | * @return $this |
||
139 | */ |
||
140 | public function flushCriteria() |
||
145 | |||
146 | /** |
||
147 | * Set default criteria list. |
||
148 | * |
||
149 | * @param array $criteria |
||
150 | * @return $this |
||
151 | */ |
||
152 | public function setDefaultCriteria(array $criteria) |
||
160 | |||
161 | /** |
||
162 | * Return default criteria list |
||
163 | * |
||
164 | * @return array |
||
165 | */ |
||
166 | public function getDefaultCriteria() |
||
170 | |||
171 | /** |
||
172 | * Return current list of criteria. |
||
173 | * |
||
174 | * @return array |
||
175 | */ |
||
176 | public function getCriteria() |
||
184 | |||
185 | /** |
||
186 | * Set skipCriteria flag. |
||
187 | * |
||
188 | * @param bool|true $flag |
||
189 | * @return $this |
||
190 | */ |
||
191 | public function skipCriteria($flag = true) |
||
196 | |||
197 | /** |
||
198 | * Set skipDefaultCriteria flag. |
||
199 | * |
||
200 | * @param bool|true $flag |
||
201 | * @return $this |
||
202 | */ |
||
203 | public function skipDefaultCriteria($flag = true) |
||
208 | |||
209 | /** |
||
210 | * Check if a given criterion name now in the criteria list. |
||
211 | * |
||
212 | * @param CriterionContract|Closure|string $criterion |
||
213 | * @return bool |
||
214 | */ |
||
215 | public function hasCriterion($criterion) |
||
219 | |||
220 | /** |
||
221 | * Return criterion object or closure from criteria list by name. |
||
222 | * |
||
223 | * @param $criterion |
||
224 | * @return CriterionContract|Closure|null |
||
225 | */ |
||
226 | public function getCriterion($criterion) |
||
234 | |||
235 | /** |
||
236 | * Apply criteria list to the given query |
||
237 | * |
||
238 | * @param $query |
||
239 | * @param $repository |
||
240 | * @return mixed |
||
241 | */ |
||
242 | public function applyCriteria($query, $repository) |
||
254 | } |
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.