[TwigBundle] Adds service check for extension loading
This commit is contained in:
parent
2453a58d56
commit
e372183b26
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bundle\TwigBundle\DependencyInjection\Compiler;
|
||||||
|
|
||||||
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
|
||||||
|
*/
|
||||||
|
class ExtensionPass implements CompilerPassInterface
|
||||||
|
{
|
||||||
|
public function process(ContainerBuilder $container)
|
||||||
|
{
|
||||||
|
if ($container->has('form.extension')) {
|
||||||
|
$container->getDefinition('twig.extension.form')->addTag('twig.extension');
|
||||||
|
$reflClass = new \ReflectionClass('Symfony\Bridge\Twig\Extension\FormExtension');
|
||||||
|
$container->getDefinition('twig.loader')->addMethodCall('addPath', array(dirname(dirname($reflClass->getFileName())).'/Resources/views/Form'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (false === $container->has('translator')) {
|
||||||
|
$container->getDefinition('twig.extension.trans')->addTag('twig.extension');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -57,9 +57,6 @@ class TwigExtension extends Extension
|
|||||||
|
|
||||||
$container->setParameter('twig.form.resources', $config['form']['resources']);
|
$container->setParameter('twig.form.resources', $config['form']['resources']);
|
||||||
|
|
||||||
$reflClass = new \ReflectionClass('Symfony\Bridge\Twig\Extension\FormExtension');
|
|
||||||
$container->getDefinition('twig.loader.filesystem')->addMethodCall('addPath', array(dirname(dirname($reflClass->getFileName())).'/Resources/views/Form'));
|
|
||||||
|
|
||||||
$twigFilesystemLoaderDefinition = $container->getDefinition('twig.loader.filesystem');
|
$twigFilesystemLoaderDefinition = $container->getDefinition('twig.loader.filesystem');
|
||||||
|
|
||||||
// register user-configured paths
|
// register user-configured paths
|
||||||
|
@ -58,7 +58,6 @@
|
|||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="twig.extension.trans" class="%twig.extension.trans.class%" public="false">
|
<service id="twig.extension.trans" class="%twig.extension.trans.class%" public="false">
|
||||||
<tag name="twig.extension" />
|
|
||||||
<argument type="service" id="translator" />
|
<argument type="service" id="translator" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
@ -93,8 +92,8 @@
|
|||||||
<argument type="service" id="fragment.handler" />
|
<argument type="service" id="fragment.handler" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
|
||||||
<service id="twig.extension.form" class="%twig.extension.form.class%" public="false">
|
<service id="twig.extension.form" class="%twig.extension.form.class%" public="false">
|
||||||
<tag name="twig.extension" />
|
|
||||||
<argument type="service" id="twig.form.renderer" />
|
<argument type="service" id="twig.form.renderer" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|||||||
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigEnvironmentPass;
|
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigEnvironmentPass;
|
||||||
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigLoaderPass;
|
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigLoaderPass;
|
||||||
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExceptionListenerPass;
|
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExceptionListenerPass;
|
||||||
|
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExtensionPass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bundle.
|
* Bundle.
|
||||||
@ -28,6 +29,7 @@ class TwigBundle extends Bundle
|
|||||||
{
|
{
|
||||||
parent::build($container);
|
parent::build($container);
|
||||||
|
|
||||||
|
$container->addCompilerPass(new ExtensionPass());
|
||||||
$container->addCompilerPass(new TwigEnvironmentPass());
|
$container->addCompilerPass(new TwigEnvironmentPass());
|
||||||
$container->addCompilerPass(new TwigLoaderPass());
|
$container->addCompilerPass(new TwigLoaderPass());
|
||||||
$container->addCompilerPass(new ExceptionListenerPass());
|
$container->addCompilerPass(new ExceptionListenerPass());
|
||||||
|
Reference in New Issue
Block a user