merged branch juliendidier/twig-security-class (PR #2835)

Commits
-------

60ebaaa [SecurityBundle] fix service class by adding a parameter, on twig extension

Discussion
----------

[SecurityBundle] fix service class by adding a parameter, on twig extension

Bug fix: no
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: -

To override the is_granted twig function, the class of TwigExtension is now set in a parameter.

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

by stof at 2011/12/10 10:38:38 -0800

First thing, you could overwrite the extension at the twig level by simply registering another twig extension with the same ``getName`` method.

And second point, replacing core Twig functions is probably one of the best way to forbid you to use third party bundles as the change will also impact their code. Do you really need to do it (especially considering that this function simply calls the security context and all the logic is in the context) ?

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

by juliendidier at 2011/12/10 15:43:08 -0800

Yes, overriding ```is_granted``` function is probably a bad example. But having it set as parameter allow you to redefine it (if you know what you are doing).
This commit is contained in:
Fabien Potencier 2011-12-19 08:06:39 +01:00
commit 30f2be3b70

View File

@ -4,8 +4,11 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="twig.extension.security.class">Symfony\Bundle\SecurityBundle\Twig\Extension\SecurityExtension</parameter>
</parameters>
<services>
<service id="twig.extension.security" class="Symfony\Bundle\SecurityBundle\Twig\Extension\SecurityExtension" public="false">
<service id="twig.extension.security" class="%twig.extension.security.class%" public="false">
<tag name="twig.extension" />
<argument type="service" id="security.context" on-invalid="ignore" />
</service>