7
7
use FRZB \Component \RequestMapper \Attribute \RequestBody ;
8
8
use FRZB \Component \RequestMapper \Data \HasHeaders ;
9
9
use FRZB \Component \RequestMapper \Helper \HeaderHelper ;
10
- use FRZB \Component \RequestMapper \Helper \ParamConverterHelper ;
11
- use FRZB \Component \RequestMapper \RequestMapper \RequestMapperInterface as Converter ;
10
+ use FRZB \Component \RequestMapper \Helper \RequestBodyHelper ;
11
+ use FRZB \Component \RequestMapper \RequestMapper \RequestMapperInterface as RequestMapper ;
12
12
use Symfony \Component \EventDispatcher \Attribute \AsEventListener ;
13
13
use Symfony \Component \HttpKernel \Event \ControllerEvent ;
14
14
use Symfony \Component \HttpKernel \KernelEvents ;
15
15
16
16
#[AsEventListener(event: KernelEvents::CONTROLLER , method: 'onKernelController ' , priority: -255 )]
17
- final class RequestMapperListener
17
+ class RequestMapperListener
18
18
{
19
19
public function __construct (
20
- private readonly Converter $ converter ,
20
+ private readonly RequestMapper $ mapper ,
21
21
) {
22
22
}
23
23
@@ -30,14 +30,14 @@ public function onKernelController(ControllerEvent $event): void
30
30
31
31
foreach ($ method ->getParameters () as $ parameter ) {
32
32
$ parameterType = (string ) $ parameter ->getType ();
33
- $ attribute = ParamConverterHelper ::getAttribute ($ parameter , $ attributes );
34
- $ isNativeRequest = is_a ( $ request, $ parameterType ) || is_subclass_of ( $ request , $ parameterType) ;
33
+ $ attribute = RequestBodyHelper ::getAttribute ($ parameter , $ attributes );
34
+ $ isNativeRequest = $ request instanceof $ parameterType ;
35
35
36
36
if (!$ attribute || $ isNativeRequest ) {
37
37
continue ;
38
38
}
39
39
40
- $ object = $ this ->converter -> convert ($ request , $ attribute );
40
+ $ object = $ this ->mapper -> map ($ request , $ attribute );
41
41
42
42
if ($ object instanceof HasHeaders) {
43
43
$ object ->setHeaders (HeaderHelper::getHeaders ($ request ));
@@ -48,10 +48,10 @@ public function onKernelController(ControllerEvent $event): void
48
48
}
49
49
50
50
/** @throws \ReflectionException */
51
- private function getReflectionMethod (mixed $ controller ): \ReflectionMethod |\ReflectionFunction
51
+ private function getReflectionMethod (array | object | callable $ controller ): \ReflectionMethod |\ReflectionFunction
52
52
{
53
53
return match (true ) {
54
- \is_array ($ controller ) => new \ReflectionMethod (/** @scrutinizer ignore-type */ ...$ controller ),
54
+ \is_array ($ controller ) => new \ReflectionMethod (...$ controller ),
55
55
\is_object ($ controller ) && \is_callable ($ controller ) => new \ReflectionMethod ($ controller , '__invoke ' ),
56
56
default => new \ReflectionFunction ($ controller ),
57
57
};
@@ -60,7 +60,7 @@ private function getReflectionMethod(mixed $controller): \ReflectionMethod|\Refl
60
60
/** @return array<RequestBody> */
61
61
private function getAttributes (\ReflectionMethod |\ReflectionFunction $ method ): array
62
62
{
63
- return ParamConverterHelper ::fromReflectionAttributes (
63
+ return RequestBodyHelper ::fromReflectionAttributes (
64
64
...$ method ->getAttributes (RequestBody::class, \ReflectionAttribute::IS_INSTANCEOF )
65
65
);
66
66
}
0 commit comments