Skip to content

Commit

Permalink
bug #20799 [TwigBundle] do not try to register incomplete definitions…
Browse files Browse the repository at this point in the history
… (xabbuh)

This PR was merged into the 2.7 branch.

Discussion
----------

[TwigBundle] do not try to register incomplete definitions

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20212
| License       | MIT
| Doc PR        |

Commits
-------

2c9dc66 do not try to register incomplete definitions
  • Loading branch information
fabpot committed Dec 17, 2016
2 parents 0a4a92b + 2c9dc66 commit 3e874dc
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 29 deletions.
Expand Up @@ -27,8 +27,14 @@ public function process(ContainerBuilder $container)
return;
}

// register the exception controller only if Twig is enabled
if ($container->hasParameter('templating.engines')) {
if (!interface_exists('Symfony\Component\Templating\TemplateReferenceInterface')) {
$container->removeDefinition('twig.controller.exception');
}

// register the exception controller only if Twig is enabled and required dependencies do exist
if (!class_exists('Symfony\Component\Debug\Exception\FlattenException') || !interface_exists('Symfony\Component\EventDispatcher\EventSubscriberInterface')) {
$container->removeDefinition('twig.exception_listener');
} elseif ($container->hasParameter('templating.engines')) {
$engines = $container->getParameter('templating.engines');
if (!in_array('twig', $engines)) {
$container->removeDefinition('twig.exception_listener');
Expand Down
Expand Up @@ -23,6 +23,25 @@ class ExtensionPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!class_exists('Symfony\Component\Asset\Packages')) {
$container->removeDefinition('twig.extension.assets');
}

if (!class_exists('Symfony\Component\ExpressionLanguage\Expression')) {
$container->removeDefinition('twig.extension.expression');
}

if (!interface_exists('Symfony\Component\Routing\Generator\UrlGeneratorInterface')) {
$container->removeDefinition('twig.extension.routing');
}
if (!interface_exists('Symfony\Component\Translation\TranslatorInterface')) {
$container->removeDefinition('twig.extension.trans');
}

if (!class_exists('Symfony\Component\Yaml\Yaml')) {
$container->removeDefinition('twig.extension.yaml');
}

if ($container->has('form.extension')) {
$container->getDefinition('twig.extension.form')->addTag('twig.extension');
$reflClass = new \ReflectionClass('Symfony\Bridge\Twig\Extension\FormExtension');
Expand Down
Expand Up @@ -36,6 +36,18 @@ public function load(array $configs, ContainerBuilder $container)
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('twig.xml');

if (class_exists('Symfony\Component\Form\Form')) {
$loader->load('form.xml');
}

if (interface_exists('Symfony\Component\Templating\EngineInterface')) {
$loader->load('templating.xml');
}

if (!interface_exists('Symfony\Component\Translation\TranslatorInterface')) {
$container->removeDefinition('twig.translation.extractor');
}

foreach ($configs as $key => $config) {
if (isset($config['globals'])) {
foreach ($config['globals'] as $name => $value) {
Expand Down
20 changes: 20 additions & 0 deletions src/Symfony/Bundle/TwigBundle/Resources/config/form.xml
@@ -0,0 +1,20 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
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">

<services>
<service id="twig.extension.form" class="%twig.extension.form.class%" public="false">
<argument type="service" id="twig.form.renderer" />
</service>

<service id="twig.form.engine" class="%twig.form.engine.class%" public="false">
<argument>%twig.form.resources%</argument>
</service>

<service id="twig.form.renderer" class="%twig.form.renderer.class%" public="false">
<argument type="service" id="twig.form.engine" />
<argument type="service" id="security.csrf.token_manager" on-invalid="null" />
</service>
</services>
</container>
21 changes: 21 additions & 0 deletions src/Symfony/Bundle/TwigBundle/Resources/config/templating.xml
@@ -0,0 +1,21 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
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">

<services>
<service id="twig.loader.filesystem" class="%twig.loader.filesystem.class%" public="false">
<argument type="service" id="templating.locator" />
<argument type="service" id="templating.name_parser" />
<tag name="twig.loader"/>
</service>

<service id="twig.loader" alias="twig.loader.filesystem" />

<service id="templating.engine.twig" class="%templating.engine.twig.class%" public="false">
<argument type="service" id="twig" />
<argument type="service" id="templating.name_parser" />
<argument type="service" id="templating.locator" />
</service>
</services>
</container>
27 changes: 0 additions & 27 deletions src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
Expand Up @@ -55,22 +55,8 @@
<argument type="collection" />
</service>

<service id="twig.loader.filesystem" class="%twig.loader.filesystem.class%" public="false">
<argument type="service" id="templating.locator" />
<argument type="service" id="templating.name_parser" />
<tag name="twig.loader"/>
</service>

<service id="twig.loader.chain" class="%twig.loader.chain.class%" public="false"/>

<service id="twig.loader" alias="twig.loader.filesystem" />

<service id="templating.engine.twig" class="%templating.engine.twig.class%" public="false">
<argument type="service" id="twig" />
<argument type="service" id="templating.name_parser" />
<argument type="service" id="templating.locator" />
</service>

<service id="twig.extension.profiler" class="Symfony\Bridge\Twig\Extension\ProfilerExtension" public="false">
<argument type="service" id="twig.profile" />
<argument type="service" id="debug.stopwatch" on-invalid="null" />
Expand Down Expand Up @@ -130,21 +116,8 @@
<argument type="service" id="router.request_context" on-invalid="ignore" />
</service>

<service id="twig.extension.form" class="%twig.extension.form.class%" public="false">
<argument type="service" id="twig.form.renderer" />
</service>

<service id="twig.extension.debug" class="Twig_Extension_Debug" public="false" />

<service id="twig.form.engine" class="%twig.form.engine.class%" public="false">
<argument>%twig.form.resources%</argument>
</service>

<service id="twig.form.renderer" class="%twig.form.renderer.class%" public="false">
<argument type="service" id="twig.form.engine" />
<argument type="service" id="security.csrf.token_manager" on-invalid="null" />
</service>

<service id="twig.translation.extractor" class="%twig.translation.extractor.class%">
<argument type="service" id="twig" />
<tag name="translation.extractor" alias="twig" />
Expand Down

0 comments on commit 3e874dc

Please sign in to comment.