Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7ac016f

Browse filesBrowse files
committed
[TwigBundle] Fix kernel bootability even if a twig extension fails on constructor
1 parent af6b25b commit 7ac016f
Copy full SHA for 7ac016f

File tree

2 files changed

+16
-3
lines changed
Filter options

2 files changed

+16
-3
lines changed

‎src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php
+15-2Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\TwigBundle\CacheWarmer;
1313

14+
use Symfony\Component\DependencyInjection\ContainerInterface;
1415
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
1516

1617
/**
@@ -20,12 +21,20 @@
2021
*/
2122
class TemplateCacheWarmer implements CacheWarmerInterface
2223
{
24+
private $container;
2325
private $twig;
2426
private $iterator;
2527

26-
public function __construct(\Twig_Environment $twig, \Traversable $iterator)
28+
public function __construct($container, \Traversable $iterator)
2729
{
28-
$this->twig = $twig;
30+
if ($container instanceof ContainerInterface) {
31+
$this->container = $container;
32+
} elseif ($container instanceof \Twig_Environement) {
33+
$this->twig = $container;
34+
} else {
35+
throw new \InvalidArgumentException(sprintf('%s only accepts instance of ContainerInterface or Twig_environment as first argument.', get_class($this)));
36+
}
37+
2938
$this->iterator = $iterator;
3039
}
3140

@@ -34,6 +43,10 @@ public function __construct(\Twig_Environment $twig, \Traversable $iterator)
3443
*/
3544
public function warmUp($cacheDir)
3645
{
46+
if (null === $this->twig) {
47+
$this->twig = $this->container->get('twig');
48+
}
49+
3750
foreach ($this->iterator as $template) {
3851
try {
3952
$this->twig->loadTemplate($template);

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
<service id="twig.template_cache_warmer" class="Symfony\Bundle\TwigBundle\CacheWarmer\TemplateCacheWarmer" public="false">
6262
<tag name="kernel.cache_warmer" />
63-
<argument type="service" id="twig" />
63+
<argument type="service" id="service_container" />
6464
<argument type="service" id="twig.template_iterator" />
6565
</service>
6666

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.