[TwigBundle] removed @ when defining an autoescaping service, and fixed XSD to use - instead of _

This commit is contained in:
Fabien Potencier 2013-04-21 10:18:50 +02:00
parent 898a63c8f0
commit 46ac2f0e42
6 changed files with 9 additions and 12 deletions

View File

@ -4,7 +4,7 @@ CHANGELOG
2.3.0
-----
* added option to configure a custom template escaping guesser
* added option to configure a custom template escaping guesser (via `autoescape_service` and `autoescape_service_method`)
2.2.0
-----

View File

@ -108,13 +108,10 @@ class TwigExtension extends Extension
$container->setAlias('debug.templating.engine.twig', 'templating.engine.twig');
}
if (isset($config['autoescape_service']) && 0 === strpos($config['autoescape_service'], '@') && isset($config['autoescape_service_method'])) {
$container->findDefinition('templating.engine.twig')->addMethodCall('setDefaultEscapingStrategy', array(array(new Reference(substr($config['autoescape_service'], 1)), $config['autoescape_service_method'])));
if (isset($config['autoescape_service']) && isset($config['autoescape_service_method'])) {
$container->findDefinition('templating.engine.twig')->addMethodCall('setDefaultEscapingStrategy', array(array(new Reference($config['autoescape_service']), $config['autoescape_service_method'])));
unset(
$config['autoescape_service'],
$config['autoescape_service_method']
);
unset($config['autoescape_service'], $config['autoescape_service_method']);
} elseif (!isset($config['autoescape'])) {
$container->findDefinition('templating.engine.twig')->addMethodCall('setDefaultEscapingStrategy', array(array(new Reference('templating.engine.twig'), 'guessDefaultEscapingStrategy')));
}

View File

@ -16,8 +16,8 @@
<xsd:attribute name="auto-reload" type="xsd:string" />
<xsd:attribute name="autoescape" type="xsd:string" />
<xsd:attribute name="autoescape_service" type="xsd:string" />
<xsd:attribute name="autoescape_service_method" type="xsd:string" />
<xsd:attribute name="autoescape-service" type="xsd:string" />
<xsd:attribute name="autoescape-service-method" type="xsd:string" />
<xsd:attribute name="base-template-class" type="xsd:string" />
<xsd:attribute name="cache" type="xsd:string" />
<xsd:attribute name="charset" type="xsd:string" />

View File

@ -1,6 +1,6 @@
<?php
$container->loadFromExtension('twig', array(
'autoescape_service' => '@my_project.some_bundle.template_escaping_guesser',
'autoescape_service' => 'my_project.some_bundle.template_escaping_guesser',
'autoescape_service_method' => 'guess',
));

View File

@ -6,5 +6,5 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd">
<twig:config autoescape_service="@my_project.some_bundle.template_escaping_guesser" autoescape_service_method="guess" />
<twig:config autoescape-service="my_project.some_bundle.template_escaping_guesser" autoescape-service-method="guess" />
</container>

View File

@ -1,3 +1,3 @@
twig:
autoescape_service: @my_project.some_bundle.template_escaping_guesser
autoescape_service: my_project.some_bundle.template_escaping_guesser
autoescape_service_method: guess