1 | <?php |
||
12 | class FilterManager |
||
13 | { |
||
14 | protected static $added_filters = []; |
||
15 | protected static $parsed_filters = []; |
||
16 | |||
17 | /** |
||
18 | * 获取应该应用的 filters. |
||
19 | * |
||
20 | * @return array |
||
21 | */ |
||
22 | public static function get() |
||
23 | { |
||
24 | $filters = array_merge(self::$added_filters, self::parseRequest()); |
||
25 | |||
26 | return array_reverse(array_unique($filters)); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * 解析请求的 filters. |
||
31 | * |
||
32 | * @return array |
||
33 | */ |
||
34 | public static function parseRequest() |
||
35 | { |
||
36 | if (self::$parsed_filters !== []) { |
||
37 | return self::$parsed_filters; |
||
38 | } |
||
39 | |||
40 | return self::$parsed_filters = explode(',', Input::get('filters')); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * 添加 filter. |
||
45 | * |
||
46 | * @param $filters |
||
47 | */ |
||
48 | public static function addFilter($filters) |
||
52 | } |
||
53 |