merged branch schmittjoh/routerFix (PR #1720)

Commits
-------

9bcce9f fix tests
fc4787a fix non-extensible router

Discussion
----------

Router fix

Right now, the router is hard to overwrite (you need always a compiler pass). This commit fixes this.

---------------------------------------------------------------------------

by fabpot at 2011/07/18 01:15:36 -0700

Why do you need a complier pass to override the router?

---------------------------------------------------------------------------

by schmittjoh at 2011/07/18 01:47:47 -0700

How would you suggest to overwrite it?

Basically, I want to do something like this:

```yml
services:
    router:
         parent: router.default
         class: MyClass
         calls:
             - [moreDeps, []]
```

---------------------------------------------------------------------------

by Seldaek at 2011/07/18 05:07:19 -0700

Then maybe we should somehow support redefining services with the same name while keeping the old one as parent, otherwise we need this foo.default for every service out there?

---------------------------------------------------------------------------

by fabpot at 2011/07/18 06:30:34 -0700

as @Seldeak said, why do that for the router and not all services?

---------------------------------------------------------------------------

by schmittjoh at 2011/07/18 06:38:39 -0700

I have designed the SecurityBundle this way where extension is encouraged.

---------------------------------------------------------------------------

by schmittjoh at 2011/07/18 11:15:57 -0700

I should add that this is mainly a problem for services where you still want to use the semantic configuration that is provided by the bundle. For services which are not configured by the extension, this is not so much of an issue.

Anyway, if you don't want to merge it, just close the PR. I have no problem with using a compiler pass.

---------------------------------------------------------------------------

by fabpot at 2011/07/18 11:55:11 -0700

We already have such a case with translator and translator.real. I will review the existing services to see where it makes sense to implement the same strategy.

---------------------------------------------------------------------------

by Seldaek at 2011/07/18 12:20:55 -0700

I guess you'd do it anyway, but we should pick a winner between .real and .default

---------------------------------------------------------------------------

by lsmith77 at 2011/07/18 12:26:52 -0700

I would prefer ".default" as ".real" always confused me.
This commit is contained in:
Fabien Potencier 2011-07-19 12:06:28 +02:00
commit d2e9f14597
3 changed files with 6 additions and 5 deletions

View File

@ -233,7 +233,7 @@ class FrameworkExtension extends Extension
$loader->load('routing.xml');
$container->setParameter('router.resource', $config['resource']);
$router = $container->findDefinition('router');
$router = $container->findDefinition('router.default');
if (isset($config['type'])) {
$argument = $router->getArgument(2);
@ -250,7 +250,7 @@ class FrameworkExtension extends Extension
'Symfony\\Component\\Routing\\Matcher\\UrlMatcher',
'Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface',
'Symfony\\Component\\Routing\\Generator\\UrlGenerator',
$container->findDefinition('router')->getClass(),
$container->findDefinition('router.default')->getClass(),
));
}

View File

@ -47,7 +47,7 @@
<argument type="service" id="routing.resolver" />
</service>
<service id="router" class="%router.class%">
<service id="router.default" class="%router.class%" public="false">
<argument type="service" id="service_container" />
<argument>%router.resource%</argument>
<argument type="collection">
@ -63,6 +63,7 @@
<argument key="matcher_cache_class">%router.options.matcher.cache_class%</argument>
</argument>
</service>
<service id="router" alias="router.default" />
<service id="router.cache_warmer" class="%router.cache_warmer.class%" public="false">
<tag name="kernel.cache_warmer" />

View File

@ -54,8 +54,8 @@ abstract class FrameworkExtensionTest extends TestCase
{
$container = $this->createContainerFromFile('full');
$this->assertTrue($container->hasDefinition('router'), '->registerRouterConfiguration() loads routing.xml');
$arguments = $container->getDefinition('router')->getArguments();
$this->assertTrue($container->has('router'), '->registerRouterConfiguration() loads routing.xml');
$arguments = $container->findDefinition('router')->getArguments();
$this->assertEquals($container->getParameter('kernel.root_dir').'/config/routing.xml', $container->getParameter('router.resource'), '->registerRouterConfiguration() sets routing resource');
$this->assertEquals('%router.resource%', $arguments[1], '->registerRouterConfiguration() sets routing resource');
$this->assertEquals('xml', $arguments[2]['resource_type'], '->registerRouterConfiguration() sets routing resource type');