1 | <?php |
||
10 | class Active |
||
11 | { |
||
12 | /** |
||
13 | * Value returned when state is "active" |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $activeValue; |
||
17 | |||
18 | /** |
||
19 | * Whether $activeValue should be reset after a check or not |
||
20 | * @var boolean |
||
21 | */ |
||
22 | protected $activeValuePersistent = false; |
||
23 | |||
24 | /** |
||
25 | * Value returned when state is "inactive" |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $inactiveValue; |
||
29 | |||
30 | /** |
||
31 | * Whether $inactiveValue should be reset after a check or not |
||
32 | * @var [type] |
||
33 | */ |
||
34 | protected $inactiveValuePersistent = false; |
||
35 | |||
36 | /** |
||
37 | * The Request instance |
||
38 | * @var \Illuminate\Http\Request |
||
39 | */ |
||
40 | protected $request; |
||
41 | |||
42 | /** |
||
43 | * Obviously: the constructor |
||
44 | * @method __construct |
||
45 | * @param \Illuminate\Http\Request $request The HTTP Request handled by Laravel |
||
46 | */ |
||
47 | public function __construct(HttpRequest $request) |
||
51 | |||
52 | /** |
||
53 | * Check whether url matches the given patterns |
||
54 | * @param string $patterns Patterns to match |
||
55 | * @return boolean |
||
56 | */ |
||
57 | public function checkUrlIs(...$patterns) |
||
61 | |||
62 | /** |
||
63 | * Check whether url contains given strings |
||
64 | * @param string $patterns |
||
65 | * @return boolean |
||
66 | */ |
||
67 | public function checkUrlHas(...$patterns) |
||
76 | |||
77 | /** |
||
78 | * Check if the current route name is the one given and the parameters match the current url |
||
79 | * @param string $route The route name to check |
||
80 | * @param array $routeparameters The route parameters, used to build the url |
||
81 | * @return boolean |
||
82 | */ |
||
83 | public function checkRouteIs($route, array $routeParameters = []) |
||
100 | |||
101 | /** |
||
102 | * Check whether the current route is one of the given routes |
||
103 | * @method checkRouteIn |
||
104 | * @param string $routes |
||
105 | * @return boolean |
||
106 | */ |
||
107 | public function checkRouteIn(...$routes) |
||
111 | |||
112 | /** |
||
113 | * Check that the parameters of the query string are exactly the ones given |
||
114 | * The test returns true if at least one given array matches the query string parameters (keys and values) |
||
115 | * @param array $parameters |
||
116 | * @return boolean |
||
117 | */ |
||
118 | public function checkQueryIs(array ...$parameters) |
||
127 | |||
128 | /** |
||
129 | * Check if query has all of the given parameters, not taking their values into account |
||
130 | * @param array $parameters |
||
131 | * @return boolean |
||
132 | */ |
||
133 | public function checkQueryHas(...$parameters) |
||
140 | |||
141 | /** |
||
142 | * Check if query parameters names are exactly the ones given in argument |
||
143 | * The order of the parameters does not matter |
||
144 | * @param string $parameters string |
||
145 | * @return boolean |
||
146 | */ |
||
147 | public function checkQueryHasOnly(...$parameters) |
||
155 | |||
156 | /** |
||
157 | * Check if query has the given parameters, with their given values |
||
158 | * @param array $parameters The parameters to check for |
||
159 | * @return boolean |
||
160 | */ |
||
161 | public function checkQueryContains($parameters) |
||
167 | |||
168 | /** |
||
169 | * Common check function |
||
170 | * @param string $check The check method to use |
||
171 | * @param array $arguments Arguments to check with |
||
172 | * @return string |
||
173 | */ |
||
174 | protected function check($check, array $arguments) |
||
178 | |||
179 | /** |
||
180 | * Returns activeValue or inactiveValue for checkUrlIs test |
||
181 | * @param string $patterns |
||
182 | * @return string Active state string |
||
183 | * @see Active::checkUrl |
||
184 | */ |
||
185 | public function ifUrlIs(...$patterns) |
||
189 | |||
190 | /** |
||
191 | * Returns activeValue or inactiveValue for checkUrlHas test |
||
192 | * @param string $patterns |
||
193 | * @return string Active state string |
||
194 | * @see Active::checkUrlHas() |
||
195 | */ |
||
196 | public function ifUrlHas(...$patterns) |
||
200 | |||
201 | /** |
||
202 | * Returns activeValue or inactiveValue for checkRouteIs test |
||
203 | * @param string $route |
||
204 | * @param array $parameters |
||
205 | * @return string Active state string |
||
206 | * @see Active::checkRouteIs() |
||
207 | */ |
||
208 | public function ifRouteIs($route, array $parameters = []) |
||
212 | |||
213 | /** |
||
214 | * Return activeValue or inactiveValue for checkRouteIn test |
||
215 | * @param string $routes |
||
216 | * @return boolean |
||
217 | * @see Active::checkRouteIn() |
||
218 | */ |
||
219 | public function ifRouteIn(...$routes) |
||
223 | |||
224 | /** |
||
225 | * Returns activeValue or inactiveValue for checkQuery test |
||
226 | * @param string $patterns |
||
227 | * @return string Active state string |
||
228 | * @see Active::checkQueryIs() |
||
229 | */ |
||
230 | public function ifQueryIs(array ...$parameters) |
||
234 | |||
235 | /** |
||
236 | * Returns activeValue or inactiveValue for checkQueryHas test |
||
237 | * @param string $patterns |
||
238 | * @return string Active state string |
||
239 | * @see Active::checkQueryHas() |
||
240 | */ |
||
241 | public function ifQueryHas(...$parameters) |
||
245 | |||
246 | /** |
||
247 | * Returns activeValue or inactiveValue for checkQueryHasOnly test |
||
248 | * @param string $patterns |
||
249 | * @return string Active state string |
||
250 | * @see Active::checkQueryHasOnly() |
||
251 | */ |
||
252 | public function ifQueryHasOnly(...$parameters) |
||
256 | |||
257 | /** |
||
258 | * Returns activeValue or inactiveValue for checkQueryContains test |
||
259 | * @param string $parameters |
||
260 | * @return string Active state string |
||
261 | * @see Active::checkQueryContains() |
||
262 | */ |
||
263 | public function ifQueryContains($parameters) |
||
267 | |||
268 | /** |
||
269 | * Returns the active state string depending on the actual state |
||
270 | * @param boolean $active |
||
271 | * @return string |
||
272 | */ |
||
273 | public function getState($active) |
||
277 | |||
278 | /** |
||
279 | * Returns the active state string |
||
280 | * @return string |
||
281 | */ |
||
282 | public function getActiveValue() |
||
290 | |||
291 | /** |
||
292 | * Return the inactive state string |
||
293 | * @return string |
||
294 | */ |
||
295 | public function getInactiveValue() |
||
303 | |||
304 | /** |
||
305 | * Set the active state string |
||
306 | * @param string $value The string value |
||
307 | * @param boolean|null $persistent Whether to reset the value after the next check |
||
308 | */ |
||
309 | public function setActiveValue($value = null, $persistent = null) |
||
316 | |||
317 | /** |
||
318 | * Set the inactive state string |
||
319 | * @param string $value The string value |
||
320 | * @param boolean|null $persistent Whether to reset the value after the next check |
||
321 | */ |
||
322 | public function setInactiveValue($value = null, $persistent = null) |
||
329 | |||
330 | /** |
||
331 | * Change active and inactive state at runtime and allow method chaining |
||
332 | * @param string $active_state |
||
333 | * @param string $inactive_state |
||
334 | * @return Active |
||
335 | */ |
||
336 | public function state(string $active_state, string $inactive_state = null) |
||
344 | |||
345 | /** |
||
346 | * Reset both active and inactive state strings |
||
347 | */ |
||
348 | public function resetValues() |
||
353 | } |
||
354 |