8000 [TwigBundle] Fix usage of TwigBundle without FrameworkBundle by tgalopin · Pull Request #28893 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[TwigBundle] Fix usage of TwigBundle without FrameworkBundle #28893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function process(ContainerBuilder $container)

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')) {
Expand All @@ -74,6 +75,10 @@ public function process(ContainerBuilder $container)
}
}

if (!$container->has('http_kernel')) {
$container->removeDefinition('twig.controller.preview_error');
}

if ($container->has('request_stack')) {
$container->getDefinition('twig.extension.httpfoundation')->addTag('twig.extension');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ public function load(array $configs, ContainerBuilder $container)
$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-& 10000 gt;getDefinition('twig.form.renderer')->setPrivate(true);
Expand Down
1 change: 0 additions & 1 deletion src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
51 changes: 51 additions & 0 deletions src/Symfony/Bundle/TwigBundle/Tests/Functional/EmptyAppTest.php
Original file line number Diff line number Diff line change
@@ -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';
}
}
0