Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[TwigBundle] Adds service check for extension loading
  • Loading branch information
jfsimon authored and fabpot committed Mar 14, 2013
1 parent 2453a58 commit e372183
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
@@ -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');
}
}
}
Expand Up @@ -57,9 +57,6 @@ public function load(array $configs, ContainerBuilder $container)

$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');

// register user-configured paths
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
Expand Up @@ -58,7 +58,6 @@
</service>

<service id="twig.extension.trans" class="%twig.extension.trans.class%" public="false">
<tag name="twig.extension" />
<argument type="service" id="translator" />
</service>

Expand Down Expand Up @@ -93,8 +92,8 @@
<argument type="service" id="fragment.handler" />
</service>


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

Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bundle/TwigBundle/TwigBundle.php
Expand Up @@ -16,6 +16,7 @@
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigEnvironmentPass;
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigLoaderPass;
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExceptionListenerPass;
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExtensionPass;

/**
* Bundle.
Expand All @@ -28,6 +29,7 @@ public function build(ContainerBuilder $container)
{
parent::build($container);

$container->addCompilerPass(new ExtensionPass());
$container->addCompilerPass(new TwigEnvironmentPass());
$container->addCompilerPass(new TwigLoaderPass());
$container->addCompilerPass(new ExceptionListenerPass());
Expand Down

0 comments on commit e372183

Please sign in to comment.