Skip to content

Commit 3e874dc

Browse files
committed
bug symfony#20799 [TwigBundle] do not try to register incomplete definitions (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 | symfony#20212 | License | MIT | Doc PR | Commits ------- 2c9dc66 do not try to register incomplete definitions
2 parents 0a4a92b + 2c9dc66 commit 3e874dc

File tree

6 files changed

+80
-29
lines changed

6 files changed

+80
-29
lines changed

src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExceptionListenerPass.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ public function process(ContainerBuilder $container)
2727
return;
2828
}
2929

30-
// register the exception controller only if Twig is enabled
31-
if ($container->hasParameter('templating.engines')) {
30+
if (!interface_exists('Symfony\Component\Templating\TemplateReferenceInterface')) {
31+
$container->removeDefinition('twig.controller.exception');
32+
}
33+
34+
// register the exception controller only if Twig is enabled and required dependencies do exist
35+
if (!class_exists('Symfony\Component\Debug\Exception\FlattenException') || !interface_exists('Symfony\Component\EventDispatcher\EventSubscriberInterface')) {
36+
$container->removeDefinition('twig.exception_listener');
37+
} elseif ($container->hasParameter('templating.engines')) {
3238
$engines = $container->getParameter('templating.engines');
3339
if (!in_array('twig', $engines)) {
3440
$container->removeDefinition('twig.exception_listener');

src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php

+19
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,25 @@ class ExtensionPass implements CompilerPassInterface
2323
{
2424
public function process(ContainerBuilder $container)
2525
{
26+
if (!class_exists('Symfony\Component\Asset\Packages')) {
27+
$container->removeDefinition('twig.extension.assets');
28+
}
29+
30+
if (!class_exists('Symfony\Component\ExpressionLanguage\Expression')) {
31+
$container->removeDefinition('twig.extension.expression');
32+
}
33+
34+
if (!interface_exists('Symfony\Component\Routing\Generator\UrlGeneratorInterface')) {
35+
$container->removeDefinition('twig.extension.routing');
36+
}
37+
if (!interface_exists('Symfony\Component\Translation\TranslatorInterface')) {
38+
$container->removeDefinition('twig.extension.trans');
39+
}
40+
41+
if (!class_exists('Symfony\Component\Yaml\Yaml')) {
42+
$container->removeDefinition('twig.extension.yaml');
43+
}
44+
2645
if ($container->has('form.extension')) {
2746
$container->getDefinition('twig.extension.form')->addTag('twig.extension');
2847
$reflClass = new \ReflectionClass('Symfony\Bridge\Twig\Extension\FormExtension');

src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php

+12
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ public function load(array $configs, ContainerBuilder $container)
3636
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
3737
$loader->load('twig.xml');
3838

39+
if (class_exists('Symfony\Component\Form\Form')) {
40+
$loader->load('form.xml');
41+
}
42+
43+
if (interface_exists('Symfony\Component\Templating\EngineInterface')) {
44+
$loader->load('templating.xml');
45+
}
46+
47+
if (!interface_exists('Symfony\Component\Translation\TranslatorInterface')) {
48+
$container->removeDefinition('twig.translation.extractor');
49+
}
50+
3951
foreach ($configs as $key => $config) {
4052
if (isset($config['globals'])) {
4153
foreach ($config['globals'] as $name => $value) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
5+
6+
<services>
7+
<service id="twig.extension.form" class="%twig.extension.form.class%" public="false">
8+
<argument type="service" id="twig.form.renderer" />
9+
</service>
10+
11+
<service id="twig.form.engine" class="%twig.form.engine.class%" public="false">
12+
<argument>%twig.form.resources%</argument>
13+
</service>
14+
15+
<service id="twig.form.renderer" class="%twig.form.renderer.class%" public="false">
16+
<argument type="service" id="twig.form.engine" />
17+
<argument type="service" id="security.csrf.token_manager" on-invalid="null" />
18+
</service>
19+
</services>
20+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
5+
6+
<services>
7+
<service id="twig.loader.filesystem" class="%twig.loader.filesystem.class%" public="false">
8+
<argument type="service" id="templating.locator" />
9+
<argument type="service" id="templating.name_parser" />
10+
<tag name="twig.loader"/>
11+
</service>
12+
13+
<service id="twig.loader" alias="twig.loader.filesystem" />
14+
15+
<service id="templating.engine.twig" class="%templating.engine.twig.class%" public="false">
16+
<argument type="service" id="twig" />
17+
<argument type="service" id="templating.name_parser" />
18+
<argument type="service" id="templating.locator" />
19+
</service>
20+
</services>
21+
</container>

src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml

-27
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,8 @@
5555
<argument type="collection" />
5656
</service>
5757

58-
<service id="twig.loader.filesystem" class="%twig.loader.filesystem.class%" public="false">
59-
<argument type="service" id="templating.locator" />
60-
<argument type="service" id="templating.name_parser" />
61-
<tag name="twig.loader"/>
62-
</service>
63-
6458
<service id="twig.loader.chain" class="%twig.loader.chain.class%" public="false"/>
6559

66-
<service id="twig.loader" alias="twig.loader.filesystem" />
67-
68-
<service id="templating.engine.twig" class="%templating.engine.twig.class%" public="false">
69-
<argument type="service" id="twig" />
70-
<argument type="service" id="templating.name_parser" />
71-
<argument type="service" id="templating.locator" />
72-
</service>
73-
7460
<service id="twig.extension.profiler" class="Symfony\Bridge\Twig\Extension\ProfilerExtension" public="false">
7561
<argument type="service" id="twig.profile" />
7662
<argument type="service" id="debug.stopwatch" on-invalid="null" />
@@ -130,21 +116,8 @@
130116
<argument type="service" id="router.request_context" on-invalid="ignore" />
131117
</service>
132118

133-
<service id="twig.extension.form" class="%twig.extension.form.class%" public="false">
134-
<argument type="service" id="twig.form.renderer" />
135-
</service>
136-
137119
<service id="twig.extension.debug" class="Twig_Extension_Debug" public="false" />
138120

139-
<service id="twig.form.engine" class="%twig.form.engine.class%" public="false">
140-
<argument>%twig.form.resources%</argument>
141-
</service>
142-
143-
<service id="twig.form.renderer" class="%twig.form.renderer.class%" public="false">
144-
<argument type="service" id="twig.form.engine" />
145-
<argument type="service" id="security.csrf.token_manager" on-invalid="null" />
146-
</service>
147-
148121
<service id="twig.translation.extractor" class="%twig.translation.extractor.class%">
149122
<argument type="service" id="twig" />
150123
<tag name="translation.extractor" alias="twig" />

0 commit comments

Comments
 (0)