1 | <?php |
||
25 | class BindingType |
||
26 | { |
||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | private $name; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | private $acceptedBindingClass; |
||
36 | |||
37 | /** |
||
38 | * @var BindingParameter[] |
||
39 | */ |
||
40 | private $parameters = array(); |
||
41 | |||
42 | /** |
||
43 | * Creates a new type. |
||
44 | * |
||
45 | * @param string $name The name of the type. |
||
46 | * @param string $bindingClass The class name of the accepted |
||
47 | * bindings. |
||
48 | * @param BindingParameter[] $parameters The parameters that can be set |
||
49 | * for a binding. |
||
50 | */ |
||
51 | 190 | public function __construct($name, $bindingClass, array $parameters = array()) |
|
74 | |||
75 | /** |
||
76 | * Returns the type's name. |
||
77 | * |
||
78 | * @return string The name of the type. |
||
79 | */ |
||
80 | 166 | public function getName() |
|
84 | |||
85 | /** |
||
86 | * Returns the parameters. |
||
87 | * |
||
88 | * @return BindingParameter[] The type parameters. |
||
89 | */ |
||
90 | 96 | public function getParameters() |
|
94 | |||
95 | /** |
||
96 | * Returns whether the type has parameters. |
||
97 | * |
||
98 | * @return bool Returns `true` if the type has parameters and `false` |
||
99 | * otherwise. |
||
100 | */ |
||
101 | 2 | public function hasParameters() |
|
105 | |||
106 | /** |
||
107 | * Returns whether the type has any required parameters. |
||
108 | * |
||
109 | * @return bool Returns `true` if the type has at least one required |
||
110 | * parameter. |
||
111 | */ |
||
112 | 2 | public function hasRequiredParameters() |
|
122 | |||
123 | /** |
||
124 | * Returns whether the type has any optional parameters. |
||
125 | * |
||
126 | * @return bool Returns `true` if the type has at least one optional |
||
127 | * parameter. |
||
128 | */ |
||
129 | 2 | public function hasOptionalParameters() |
|
139 | |||
140 | /** |
||
141 | * Returns a parameter by name. |
||
142 | * |
||
143 | * @param string $name The parameter name. |
||
144 | * |
||
145 | * @return BindingParameter The parameter. |
||
146 | * |
||
147 | * @throws NoSuchParameterException If the parameter was not found. |
||
148 | */ |
||
149 | 7 | public function getParameter($name) |
|
161 | |||
162 | /** |
||
163 | * Returns whether a parameter exists. |
||
164 | * |
||
165 | * @param string $name The parameter name. |
||
166 | * |
||
167 | * @return bool Returns `true` if a parameter with that name exists. |
||
168 | */ |
||
169 | 33 | public function hasParameter($name) |
|
173 | |||
174 | /** |
||
175 | * Returns the default values of the parameters. |
||
176 | * |
||
177 | * @return array The default values of the parameters. |
||
178 | */ |
||
179 | 95 | public function getParameterValues() |
|
191 | |||
192 | /** |
||
193 | * Returns whether the type has parameters with default values. |
||
194 | * |
||
195 | * @return bool Returns `true` if at least one parameter has a default value |
||
196 | * and `false` otherwise. |
||
197 | */ |
||
198 | 2 | public function hasParameterValues() |
|
208 | |||
209 | /** |
||
210 | * Returns the default value of a parameter. |
||
211 | * |
||
212 | * @param string $name The parameter name. |
||
213 | * |
||
214 | * @return mixed The default value. |
||
215 | * |
||
216 | * @throws NoSuchParameterException If the parameter was not found. |
||
217 | */ |
||
218 | 3 | public function getParameterValue($name) |
|
222 | |||
223 | /** |
||
224 | * Returns whether a parameter has a default value set. |
||
225 | * |
||
226 | * @param string $name The parameter name. |
||
227 | * |
||
228 | * @return bool Returns `true` if the parameter has a default value set and |
||
229 | * `false` otherwise. |
||
230 | * |
||
231 | * @throws NoSuchParameterException If the parameter was not found. |
||
232 | */ |
||
233 | 2 | public function hasParameterValue($name) |
|
237 | |||
238 | /** |
||
239 | * Returns whether the type accepts a binding class. |
||
240 | * |
||
241 | * @param Binding|string $binding The binding or the fully-qualified name of |
||
242 | * the binding class. |
||
243 | * |
||
244 | * @return bool Returns `true` if the binding can be bound to this type and |
||
245 | * `false` otherwise. |
||
246 | */ |
||
247 | 105 | public function acceptsBinding($binding) |
|
253 | |||
254 | /** |
||
255 | * Returns the binding class names that can be bound to this type. |
||
256 | * |
||
257 | * Returns an empty array if any binding can be bound to the type. |
||
258 | * |
||
259 | * @return string[] An array of class names or an empty array. |
||
|
|||
260 | */ |
||
261 | 1 | public function getAcceptedBindingClass() |
|
265 | } |
||
266 |
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.