Skip to content

Commit 1777fe4

Browse files
Ian Phillipslsmith77
authored andcommitted
Allow the user to typehint using ParamFetcherInterface
1 parent 7aa99c5 commit 1777fe4

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

EventListener/ParamFetcherListener.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function onKernelController(FilterControllerEvent $event)
7777
/**
7878
* Determines which attribute the ParamFetcher should be injected as.
7979
*
80-
* @param array $controller The controller action an an "array" callable.
80+
* @param array $controller The controller action as an "array" callable.
8181
*
8282
* @return string
8383
*/
@@ -109,7 +109,7 @@ private function isParamFetcherType(\ReflectionParameter $controllerParam)
109109
if (null === $type) {
110110
return false;
111111
}
112-
113-
return 'FOS\\RestBundle\\Request\\ParamFetcher' === $type->getName();
112+
$fetcherInterface = 'FOS\\RestBundle\\Request\\ParamFetcherInterface';
113+
return $type->implementsInterface($fetcherInterface);
114114
}
115115
}

Tests/EventListener/ParamFetcherListenerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ public function setParamFetcherByTypehintProvider()
138138
// the parameter name is.
139139
array('byTypeAction', 'pf'),
140140

141+
// The user can typehint using ParamFetcherInterface, too.
142+
array('byInterfaceAction', 'pfi'),
143+
141144
// If there is no controller argument for the ParamFetcher, it
142145
// should be injected as the default name.
143146
array('notProvidedAction', 'paramFetcher'),

Tests/Fixtures/Controller/ParamFetcherController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace FOS\RestBundle\Tests\Fixtures\Controller;
44

55
use FOS\RestBundle\Request\ParamFetcher;
6+
use FOS\RestBundle\Request\ParamFetcherInterface;
67

78
/**
89
* Fixture for testing whether the ParamFetcher can be injected into
@@ -22,6 +23,13 @@ public function byNameAction($paramFetcher)
2223
public function byTypeAction(ParamFetcher $pf)
2324
{}
2425

26+
/**
27+
* Make sure the ParamFetcher can be injected if the typehint is for
28+
* the interface.
29+
*/
30+
public function byInterfaceAction(ParamFetcherInterface $pfi)
31+
{}
32+
2533
/**
2634
* Make sure the ParamFetcher can be set as a request attribute even if
2735
* there is no controller parameter to receive it.

0 commit comments

Comments
 (0)