[TwigBundle] Fix usage of TwigBundle without FrameworkBundle

This commit is contained in:
Titouan Galopin 2018-10-16 18:30:52 +02:00 committed by Fabien Potencier
parent fdc9e0993f
commit 246a905f93
4 changed files with 60 additions and 2 deletions

View File

@ -64,6 +64,7 @@ class ExtensionPass implements CompilerPassInterface
if ($container->has('fragment.handler')) {
$container->getDefinition('twig.extension.httpkernel')->addTag('twig.extension');
$container->getDefinition('twig.runtime.httpkernel')->addTag('twig.runtime');
// inject Twig in the hinclude service if Twig is the only registered templating engine
if ((!$container->hasParameter('templating.engines') || array('twig') == $container->getParameter('templating.engines')) && $container->hasDefinition('fragment.renderer.hinclude')) {
@ -74,6 +75,10 @@ class ExtensionPass implements CompilerPassInterface
}
}
if (!$container->has('http_kernel')) {
$container->removeDefinition('twig.controller.preview_error');
}
if ($container->has('request_stack')) {
$container->getDefinition('twig.extension.httpfoundation')->addTag('twig.extension');
}

View File

@ -36,11 +36,14 @@ class TwigExtension extends Extension
$loader->load('twig.xml');
$container->getDefinition('twig.profile')->setPrivate(true);
$container->getDefinition('twig.runtime.httpkernel')->setPrivate(true);
$container->getDefinition('twig.translation.extractor')->setPrivate(true);
$container->getDefinition('workflow.twig_extension')->setPrivate(true);
$container->getDefinition('twig.exception_listener')->setPrivate(true);
if ($container->has('fragment.handler')) {
$container->getDefinition('twig.runtime.httpkernel')->setPrivate(true);
}
if (class_exists('Symfony\Component\Form\Form')) {
$loader->load('form.xml');
$container->getDefinition('twig.form.renderer')->setPrivate(true);

View File

@ -105,7 +105,6 @@
<service id="twig.runtime.httpkernel" class="Symfony\Bridge\Twig\Extension\HttpKernelRuntime">
<argument type="service" id="fragment.handler" />
<tag name="twig.runtime" />
</service>
<service id="twig.extension.httpfoundation" class="Symfony\Bridge\Twig\Extension\HttpFoundationExtension">

View File

@ -0,0 +1,51 @@
<?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\Tests\Functional;
use Symfony\Bundle\TwigBundle\Tests\TestCase;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;
class EmptyAppTest extends TestCase
{
public function testBootEmptyApp()
{
$kernel = new EmptyAppKernel('test', true);
$kernel->boot();
$this->assertTrue($kernel->getContainer()->hasParameter('twig.default_path'));
$this->assertNotEmpty($kernel->getContainer()->getParameter('twig.default_path'));
}
}
class EmptyAppKernel extends Kernel
{
public function registerBundles()
{
return array(new TwigBundle());
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
}
public function getCacheDir()
{
return sys_get_temp_dir().'/'.Kernel::VERSION.'/EmptyAppKernel/cache/'.$this->environment;
}
public function getLogDir()
{
return sys_get_temp_dir().'/'.Kernel::VERSION.'/EmptyAppKernel/logs';
}
}