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

Skip to content

Commit 246a905

Browse files
tgalopinfabpot
authored andcommitted
[TwigBundle] Fix usage of TwigBundle without FrameworkBundle
1 parent fdc9e09 commit 246a905

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public function process(ContainerBuilder $container)
6464

6565
if ($container->has('fragment.handler')) {
6666
$container->getDefinition('twig.extension.httpkernel')->addTag('twig.extension');
67+
$container->getDefinition('twig.runtime.httpkernel')->addTag('twig.runtime');
6768

6869
// inject Twig in the hinclude service if Twig is the only registered templating engine
6970
if ((!$container->hasParameter('templating.engines') || array('twig') == $container->getParameter('templating.engines')) && $container->hasDefinition('fragment.renderer.hinclude')) {
@@ -74,6 +75,10 @@ public function process(ContainerBuilder $container)
7475
}
7576
}
7677

78+
if (!$container->has('http_kernel')) {
79+
$container->removeDefinition('twig.controller.preview_error');
80+
}
81+
7782
if ($container->has('request_stack')) {
7883
$container->getDefinition('twig.extension.httpfoundation')->addTag('twig.extension');
7984
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ public function load(array $configs, ContainerBuilder $container)
3636
$loader->load('twig.xml');
3737

3838
$container->getDefinition('twig.profile')->setPrivate(true);
39-
$container->getDefinition('twig.runtime.httpkernel')->setPrivate(true);
4039
$container->getDefinition('twig.translation.extractor')->setPrivate(true);
4140
$container->getDefinition('workflow.twig_extension')->setPrivate(true);
4241
$container->getDefinition('twig.exception_listener')->setPrivate(true);
4342

43+
if ($container->has('fragment.handler')) {
44+
$container->getDefinition('twig.runtime.httpkernel')->setPrivate(true);
45+
}
46+
4447
if (class_exists('Symfony\Component\Form\Form')) {
4548
$loader->load('form.xml');
4649
$container->getDefinition('twig.form.renderer')->setPrivate(true);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@
105105

106106
<service id="twig.runtime.httpkernel" class="Symfony\Bridge\Twig\Extension\HttpKernelRuntime">
107107
<argument type="service" id="fragment.handler" />
108-
<tag name="twig.runtime" />
109108
</service>
110109

111110
<service id="twig.extension.httpfoundation" class="Symfony\Bridge\Twig\Extension\HttpFoundationExtension">
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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\Tests\Functional;
13+
14+
use Symfony\Bundle\TwigBundle\Tests\TestCase;
15+
use Symfony\Bundle\TwigBundle\TwigBundle;
16+
use Symfony\Component\Config\Loader\LoaderInterface;
17+
use Symfony\Component\HttpKernel\Kernel;
18+
19+
class EmptyAppTest extends TestCase
20+
{
21+
public function testBootEmptyApp()
22+
{
23+
$kernel = new EmptyAppKernel('test', true);
24+
$kernel->boot();
25+
26+
$this->assertTrue($kernel->getContainer()->hasParameter('twig.default_path'));
27+
$this->assertNotEmpty($kernel->getContainer()->getParameter('twig.default_path'));
28+
}
29+
}
30+
31+
class EmptyAppKernel extends Kernel
32+
{
33+
public function registerBundles()
34+
{
35+
return array(new TwigBundle());
36+
}
37+
38+
public function registerContainerConfiguration(LoaderInterface $loader)
39+
{
40+
}
41+
42+
public function getCacheDir()
43+
{
44+
return sys_get_temp_dir().'/'.Kernel::VERSION.'/EmptyAppKernel/cache/'.$this->environment;
45+
}
46+
47+
public function getLogDir()
48+
{
49+
return sys_get_temp_dir().'/'.Kernel::VERSION.'/EmptyAppKernel/logs';
50+
}
51+
}

0 commit comments

Comments
 (0)