File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
src/Slim/Handlers/Strategies Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1818use Psr \Http \Message \UploadedFileInterface ;
1919use ReflectionClass ;
2020use ReflectionException ;
21+ use ReflectionNamedType ;
2122use ReflectionParameter ;
2223use Slim \Interfaces \InvocationStrategyInterface ;
2324
@@ -166,6 +167,13 @@ protected function buildParams(
166167 "Missing or null required parameter ' {$ name }' in " . $ r ->getName () . ":: " . $ m ->getName ()
167168 );
168169 }
170+ $ paramType = $ param ->getType ();
171+ if ($ paramType instanceof ReflectionNamedType) {
172+ $ paramTypeName = $ paramType ->getName ();
173+ if ($ paramTypeName === 'bool ' ) {
174+ $ paramValue = $ this ->toBool ($ paramValue );
175+ }
176+ }
169177 $ buildParams [] = $ paramValue ;
170178 }
171179 }
@@ -246,4 +254,23 @@ protected function callHandler(
246254
247255 return $ response ;
248256 }
257+
258+ protected function toBool ($ value ): bool
259+ {
260+ if (is_string ($ value )) {
261+ $ value = strtolower ($ value );
262+ }
263+ return in_array ($ value , [
264+ true ,
265+ 1 ,
266+ 'true ' ,
267+ '1 ' ,
268+ 'on ' ,
269+ 'checked ' ,
270+ 'selected ' ,
271+ 'active ' ,
272+ 'yes ' ,
273+ 'oui ' ,
274+ ], true );
275+ }
249276}
You can’t perform that action at this time.
0 commit comments