Skip to content

Commit

Permalink
bug #13476 [TwigBundle] fixed Twig options (removed the parameter as …
Browse files Browse the repository at this point in the history
…it cannot contain service references) (fabpot)

This PR was merged into the 2.7 branch.

Discussion
----------

[TwigBundle] fixed Twig options (removed the parameter as it cannot contain service references)

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | no
| Fixed tickets | #13467
| License       | MIT
| Doc PR        | n/a

The new `autoescape_service` option is used to set the `autoescape` Twig option, which can be a callable. The Twig options are stored in a parameter (`twig.options`), but as parameters cannot have references, that does not work well.

So, this PR removed the parameter as it is not needed.

Commits
-------

69748a1 [TwigBundle] fixed Twig options (removed the parameter as it cannot contain service references)
  • Loading branch information
fabpot committed Jan 30, 2015
2 parents 2893180 + 69748a1 commit d5e8ee3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Expand Up @@ -106,7 +106,7 @@ public function load(array $configs, ContainerBuilder $container)
}
unset($config['autoescape_service'], $config['autoescape_service_method']);

$container->setParameter('twig.options', $config);
$container->getDefinition('twig')->replaceArgument(1, $config);

$this->addClassesToCompile(array(
'Twig_Environment',
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
Expand Up @@ -31,7 +31,7 @@
<services>
<service id="twig" class="%twig.class%">
<argument type="service" id="twig.loader" />
<argument>%twig.options%</argument>
<argument /> <!-- Twig options -->
<call method="addGlobal">
<argument>app</argument>
<argument type="service" id="twig.app_variable" />
Expand Down
Expand Up @@ -73,10 +73,10 @@ public function testLoadEmptyConfiguration()
$this->assertContains('form_div_layout.html.twig', $container->getParameter('twig.form.resources'), '->load() includes default template for form resources');

// Twig options
$options = $container->getParameter('twig.options');
$this->assertEquals(__DIR__.'/twig', $options['cache'], '->load() sets default value for cache option');
$this->assertEquals('UTF-8', $options['charset'], '->load() sets default value for charset option');
$this->assertFalse($options['debug'], '->load() sets default value for debug option');
$options = $container->getDefinition('twig')->getArgument(1);
$this->assertEquals('%kernel.cache_dir%/twig', $options['cache'], '->load() sets default value for cache option');
$this->assertEquals('%kernel.charset%', $options['charset'], '->load() sets default value for charset option');
$this->assertEquals('%kernel.debug%', $options['debug'], '->load() sets default value for debug option');
}

/**
Expand Down Expand Up @@ -114,7 +114,7 @@ public function testLoadFullConfiguration($format)
}

// Twig options
$options = $container->getParameter('twig.options');
$options = $container->getDefinition('twig')->getArgument(1);
$this->assertTrue($options['auto_reload'], '->load() sets the auto_reload option');
$this->assertTrue($options['autoescape'], '->load() sets the autoescape option');
$this->assertEquals('stdClass', $options['base_template_class'], '->load() sets the base_template_class option');
Expand All @@ -134,7 +134,7 @@ public function testLoadCustomTemplateEscapingGuesserConfiguration($format)
$this->loadFromFile($container, 'customTemplateEscapingGuesser', $format);
$this->compileContainer($container);

$options = $container->getParameter('twig.options');
$options = $container->getDefinition('twig')->getArgument(1);
$this->assertEquals(array(new Reference('my_project.some_bundle.template_escaping_guesser'), 'guess'), $options['autoescape']);
}

Expand All @@ -148,7 +148,7 @@ public function testLoadDefaultTemplateEscapingGuesserConfiguration($format)
$this->loadFromFile($container, 'empty', $format);
$this->compileContainer($container);

$options = $container->getParameter('twig.options');
$options = $container->getDefinition('twig')->getArgument(1);
$this->assertEquals('filename', $options['autoescape']);
}

Expand Down

0 comments on commit d5e8ee3

Please sign in to comment.