Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e372183

Browse files
jfsimonfabpot
authored andcommitted
[TwigBundle] Adds service check for extension loading
1 parent 2453a58 commit e372183

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\TwigBundle\DependencyInjection\Compiler;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
17+
/**
18+
* @author Jean-François Simon <[email protected]>
19+
*/
20+
class ExtensionPass implements CompilerPassInterface
21+
{
22+
public function process(ContainerBuilder $container)
23+
{
24+
if ($container->has('form.extension')) {
25+
$container->getDefinition('twig.extension.form')->addTag('twig.extension');
26+
$reflClass = new \ReflectionClass('Symfony\Bridge\Twig\Extension\FormExtension');
27+
$container->getDefinition('twig.loader')->addMethodCall('addPath', array(dirname(dirname($reflClass->getFileName())).'/Resources/views/Form'));
28+
}
29+
30+
if (false === $container->has('translator')) {
31+
$container->getDefinition('twig.extension.trans')->addTag('twig.extension');
32+
}
33+
}
34+
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ public function load(array $configs, ContainerBuilder $container)
5757

5858
$container->setParameter('twig.form.resources', $config['form']['resources']);
5959

60-
$reflClass = new \ReflectionClass('Symfony\Bridge\Twig\Extension\FormExtension');
61-
$container->getDefinition('twig.loader.filesystem')->addMethodCall('addPath', array(dirname(dirname($reflClass->getFileName())).'/Resources/views/Form'));
62-
6360
$twigFilesystemLoaderDefinition = $container->getDefinition('twig.loader.filesystem');
6461

6562
// register user-configured paths

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
</service>
5959

6060
<service id="twig.extension.trans" class="%twig.extension.trans.class%" public="false">
61-
<tag name="twig.extension" />
6261
<argument type="service" id="translator" />
6362
</service>
6463

@@ -93,8 +92,8 @@
9392
<argument type="service" id="fragment.handler" />
9493
</service>
9594

95+
9696
<service id="twig.extension.form" class="%twig.extension.form.class%" public="false">
97-
<tag name="twig.extension" />
9897
<argument type="service" id="twig.form.renderer" />
9998
</service>
10099

src/Symfony/Bundle/TwigBundle/TwigBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigEnvironmentPass;
1717
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigLoaderPass;
1818
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExceptionListenerPass;
19+
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExtensionPass;
1920

2021
/**
2122
* Bundle.
@@ -28,6 +29,7 @@ public function build(ContainerBuilder $container)
2829
{
2930
parent::build($container);
3031

32+
$container->addCompilerPass(new ExtensionPass());
3133
$container->addCompilerPass(new TwigEnvironmentPass());
3234
$container->addCompilerPass(new TwigLoaderPass());
3335
$container->addCompilerPass(new ExceptionListenerPass());

0 commit comments

Comments
 (0)