File tree Expand file tree Collapse file tree 3 files changed +18
-12
lines changed
Expand file tree Collapse file tree 3 files changed +18
-12
lines changed Original file line number Diff line number Diff line change 2323 */
2424final class ParamReader implements ParamReaderInterface
2525{
26+ /**
27+ * @var Reader|null
28+ */
2629 private $ annotationReader ;
2730
28- public function __construct (Reader $ annotationReader )
31+ public function __construct (? Reader $ annotationReader = null )
2932 {
3033 $ this ->annotationReader = $ annotationReader ;
3134 }
@@ -55,10 +58,12 @@ public function getParamsFromMethod(\ReflectionMethod $method): array
5558 $ annotations = $ this ->getParamsFromAttributes ($ method );
5659 }
5760
58- $ annotations = array_merge (
59- $ annotations ,
60- $ this ->annotationReader ->getMethodAnnotations ($ method ) ?? []
61- );
61+ if (null !== $ this ->annotationReader ) {
62+ $ annotations = array_merge (
63+ $ annotations ,
64+ $ this ->annotationReader ->getMethodAnnotations ($ method ) ?? []
65+ );
66+ }
6267
6368 return $ this ->getParamsFromAnnotationArray ($ annotations );
6469 }
@@ -73,10 +78,12 @@ public function getParamsFromClass(\ReflectionClass $class): array
7378 $ annotations = $ this ->getParamsFromAttributes ($ class );
7479 }
7580
76- $ annotations = array_merge (
77- $ annotations ,
78- $ this ->annotationReader ->getClassAnnotations ($ class ) ?? []
79- );
81+ if (null !== $ this ->annotationReader ) {
82+ $ annotations = array_merge (
83+ $ annotations ,
84+ $ this ->annotationReader ->getClassAnnotations ($ class ) ?? []
85+ );
86+ }
8087
8188 return $ this ->getParamsFromAnnotationArray ($ annotations );
8289 }
Original file line number Diff line number Diff line change 1616 <service id =" FOS\RestBundle\Request\ParamFetcherInterface" alias =" fos_rest.request.param_fetcher" />
1717
1818 <service id =" fos_rest.request.param_fetcher.reader" class =" FOS\RestBundle\Request\ParamReader" public =" false" >
19- <argument type =" service" id =" annotation_reader" />
19+ <argument type =" service" id =" annotation_reader" on-invalid = " null " />
2020 </service >
2121
2222 </services >
Original file line number Diff line number Diff line change @@ -98,8 +98,7 @@ public function testReadsOnlyParamAnnotations()
9898 */
9999 public function testReadsAttributes ()
100100 {
101- $ annotationReader = $ this ->getMockBuilder (AnnotationReader::class)->getMock ();
102- $ paramReader = new ParamReader ($ annotationReader );
101+ $ paramReader = new ParamReader ();
103102 $ params = $ paramReader ->read (new \ReflectionClass (ParamsAnnotatedController::class), 'getArticlesAttributesAction ' );
104103
105104 $ this ->assertCount (6 , $ params );
You can’t perform that action at this time.
0 commit comments