1 | <?php |
||
10 | class Filter |
||
11 | { |
||
12 | /** |
||
13 | * An array of arguments passed to the program. |
||
14 | * |
||
15 | * @var Argument[] $arguments |
||
16 | */ |
||
17 | protected $arguments = []; |
||
18 | |||
19 | /** |
||
20 | * Set the arguments to filter. |
||
21 | * |
||
22 | * @param array $arguments |
||
23 | */ |
||
24 | 9 | public function setArguments($arguments = []) |
|
28 | |||
29 | /** |
||
30 | * Callback function to check if the argument has a short prefix. |
||
31 | * |
||
32 | * @param $argument |
||
33 | * @return mixed |
||
34 | */ |
||
35 | 9 | public function hasShortPrefix($argument) |
|
39 | |||
40 | /** |
||
41 | * Callback function to check if the argument has a long prefix. |
||
42 | * |
||
43 | * @param $argument |
||
44 | * @return mixed |
||
45 | */ |
||
46 | 9 | public function hasLongPrefix($argument) |
|
50 | |||
51 | /** |
||
52 | * Callback function to check if the argument is required. |
||
53 | * |
||
54 | * @param $argument |
||
55 | * @return mixed |
||
56 | */ |
||
57 | 2 | protected function isRequired($argument) |
|
61 | |||
62 | /** |
||
63 | * Callback function to check if the argument does not had the required option. |
||
64 | * |
||
65 | * @param $argument |
||
66 | * @return bool |
||
67 | */ |
||
68 | 2 | protected function isOptional($argument) |
|
72 | |||
73 | /** |
||
74 | * Return all required arguments, these are arguments with required => true, |
||
75 | * |
||
76 | * @return Argument[] arguments with arguments set required to true |
||
77 | */ |
||
78 | 2 | public function required() |
|
82 | |||
83 | /** |
||
84 | * Return all arguments without required => true. |
||
85 | * |
||
86 | * @return Argument[] arguments with arguments set required to false |
||
87 | */ |
||
88 | 2 | public function optional() |
|
92 | |||
93 | /** |
||
94 | * Return an array with short prefixes. |
||
95 | * |
||
96 | * @return Argument[] arguments with a short prefix (e.x -u) |
||
97 | */ |
||
98 | 9 | public function withShortPrefix() |
|
102 | |||
103 | /** |
||
104 | * Return an array with long prefixes |
||
105 | * |
||
106 | * @return Argument[] required arguments (e.x --user) |
||
107 | */ |
||
108 | 9 | public function withLongPrefix() |
|
112 | |||
113 | /** |
||
114 | * This function will do the actual filtering. Call backs for array_filter |
||
115 | * will be in this function for example isRequired. |
||
116 | * |
||
117 | * @param array $filters |
||
118 | * @return array |
||
119 | */ |
||
120 | 9 | protected function filterArguments($filters = []) |
|
129 | } |