1 | <?php |
||
14 | trait ConvertsParameters |
||
15 | { |
||
16 | /** |
||
17 | * Check if an input element is set on the request. |
||
18 | * |
||
19 | * @param string $key |
||
20 | * @return bool |
||
21 | */ |
||
22 | public function __isset( $key ) |
||
26 | |||
27 | /** |
||
28 | * Get an input element from the request. |
||
29 | * |
||
30 | * @param string $key |
||
31 | * @return mixed |
||
32 | */ |
||
33 | public function __get( $key ) |
||
37 | |||
38 | /** |
||
39 | * Get the validator instance for the request. |
||
40 | * |
||
41 | * @return \Illuminate\Contracts\Validation\Validator |
||
42 | */ |
||
43 | protected function getValidatorInstance() |
||
49 | |||
50 | /** |
||
51 | * Get the input source for the request. |
||
52 | * |
||
53 | * @return \Symfony\Component\HttpFoundation\ParameterBag |
||
54 | */ |
||
55 | abstract protected function getInputSource(); |
||
56 | |||
57 | /** |
||
58 | * Cast and convert parameters. |
||
59 | * |
||
60 | * @return array |
||
61 | */ |
||
62 | protected function getConvertedParameters():array |
||
74 | |||
75 | /** |
||
76 | * Get all of the input and files for the request. |
||
77 | * |
||
78 | * @return array |
||
79 | */ |
||
80 | abstract public function all(); |
||
81 | |||
82 | /** |
||
83 | * Cast all string booleans to real boolean values. |
||
84 | * |
||
85 | * @param mixed $input |
||
86 | * @return array |
||
87 | */ |
||
88 | protected function castBooleans( $input ):array |
||
102 | |||
103 | /** |
||
104 | * Cast a given value to a boolean if it is in fact a boolean. |
||
105 | * |
||
106 | * @param mixed $value |
||
107 | * @return mixed |
||
108 | */ |
||
109 | protected function castValueToBoolean( $value ) |
||
121 | |||
122 | /** |
||
123 | * Convert a string or array to snake case. |
||
124 | * |
||
125 | * @param mixed $input |
||
126 | * @return mixed |
||
127 | */ |
||
128 | protected function convertToSnakeCase( $input ) |
||
138 | |||
139 | /** |
||
140 | * Convert all keys of an array to snake case. |
||
141 | * |
||
142 | * @param array $input |
||
143 | * @return array |
||
144 | */ |
||
145 | protected function convertArrayToSnakeCase( array $input ):array |
||
155 | } |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.