Permalink
Browse files

added support for resolving @BundleName\Filename syntax

  • Loading branch information...
1 parent c1c3a6e commit b01ca2ddc62e07105ca0a3701f36f239e29d63a3 @lsmith77 lsmith77 committed Aug 6, 2012
@@ -6,7 +6,6 @@
<parameters>
- <parameter key="fos_rest.routing.loader_2_0.controller.class">FOS\RestBundle\Routing\Loader\RestRouteLoader20</parameter>
<parameter key="fos_rest.routing.loader.controller.class">FOS\RestBundle\Routing\Loader\RestRouteLoader</parameter>
<parameter key="fos_rest.routing.loader.yaml_collection.class">FOS\RestBundle\Routing\Loader\RestYamlCollectionLoader</parameter>
<parameter key="fos_rest.routing.loader.xml_collection.class">FOS\RestBundle\Routing\Loader\RestXmlCollectionLoader</parameter>
@@ -20,6 +19,7 @@
<service id="fos_rest.routing.loader.controller" class="%fos_rest.routing.loader.controller.class%">
<argument type="service" id="service_container" />
+ <argument type="service" id="file_locator" />
<argument type="service" id="controller_name_converter" />
<argument type="service" id="fos_rest.routing.loader.reader.controller" />
<argument>%fos_rest.routing.loader.default_format%</argument>
@@ -15,6 +15,7 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Config\Loader\Loader;
+use Symfony\Component\Config\FileLocatorInterface;
use FOS\RestBundle\Routing\Loader\Reader\RestControllerReader;
@@ -30,20 +31,24 @@ class RestRouteLoader extends Loader
protected $controllerParser;
protected $controllerReader;
protected $defaultFormat;
+ protected $locator;
/**
* Initializes loader.
*
* @param ContainerInterface $container service container
+ * @param FileLocatorInterface $locator A FileLocatorInterface instance
* @param ControllerNameParser $controllerParser controller name parser
* @param RestControllerReader $controllerReader controller reader
* @param string $defaultFormat default http format
*/
public function __construct(ContainerInterface $container,
+ FileLocatorInterface $locator,
ControllerNameParser $controllerParser,
RestControllerReader $controllerReader, $defaultFormat = 'html')
{
$this->container = $container;
+ $this->locator = $locator;
$this->controllerParser = $controllerParser;
$this->controllerReader = $controllerReader;
$this->defaultFormat = $defaultFormat;
@@ -105,6 +110,11 @@ private function getControllerLocator($controller)
$class = null;
$prefix = null;
+ if (0 === strpos($controller, '@')) {
+ $file = $this->locator->locate($controller);
+ $controller = $this->findClass($file);
+ }
+
if (class_exists($controller)) {
// full class name
$class = $controller;
@@ -183,11 +183,12 @@ private function assertValidRestRouteLoader(Definition $loader, $loaderClassPara
$arguments = $loader->getArguments();
$this->assertEquals('%' . $loaderClassParameter . '%', $loader->getClass());
- $this->assertEquals(4, count($arguments));
+ $this->assertEquals(5, count($arguments));
$this->assertEquals('service_container', (string) $arguments[0]);
- $this->assertEquals('controller_name_converter', (string) $arguments[1]);
- $this->assertEquals('fos_rest.routing.loader.reader.controller', (string) $arguments[2]);
- $this->assertEquals('%fos_rest.routing.loader.default_format%', (string) $arguments[3]);
+ $this->assertEquals('file_locator', (string) $arguments[1]);
+ $this->assertEquals('controller_name_converter', (string) $arguments[2]);
+ $this->assertEquals('fos_rest.routing.loader.reader.controller', (string) $arguments[3]);
+ $this->assertEquals('%fos_rest.routing.loader.default_format%', (string) $arguments[4]);
$this->assertArrayHasKey('routing.loader', $loader->getTags());
}
@@ -47,6 +47,9 @@ protected function getControllerLoader()
$c = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
->disableOriginalConstructor()
->getMock();
+ $l = $this->getMockBuilder('Symfony\Component\Config\FileLocator')
+ ->disableOriginalConstructor()
+ ->getMock();
$p = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser')
->disableOriginalConstructor()
->getMock();
@@ -57,6 +60,6 @@ protected function getControllerLoader()
$ar = new RestActionReader($annotationReader, $paramReader);
$cr = new RestControllerReader($ar, $annotationReader);
- return new RestRouteLoader($c, $p, $cr, 'html');
+ return new RestRouteLoader($c, $l, $p, $cr, 'html');
}
}

0 comments on commit b01ca2d

Please sign in to comment.