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 2050e03

Browse filesBrowse files
committed
Fix optional cache warmers are always instantiated whereas they should be lazy-loaded
1 parent af6b25b commit 2050e03
Copy full SHA for 2050e03

File tree

Expand file treeCollapse file tree

4 files changed

+44
-12
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+44
-12
lines changed

‎src/Symfony/Bundle/FrameworkBundle/CacheWarmer/RouterCacheWarmer.php

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

1212
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
1313

14+
use Symfony\Component\DependencyInjection\ContainerInterface;
1415
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
1516
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
1617
use Symfony\Component\Routing\RouterInterface;
@@ -22,16 +23,18 @@
2223
*/
2324
class RouterCacheWarmer implements CacheWarmerInterface
2425
{
26+
private $container;
2527
protected $router;
2628

27-
/**
28-
* Constructor.
29-
*
30-
* @param RouterInterface $router A Router instance
31-
*/
32-
public function __construct(RouterInterface $router)
29+
public function __construct($container)
3330
{
34-
$this->router = $router;
31+
if ($container instanceof ContainerInterface) {
32+
$this->container = $container;
33+
} elseif ($container instanceof RouterInterface) {
34+
$this->router = $container;
35+
} else {
36+
throw new \InvalidArgumentException(sprintf('%s only accepts instance of Symfony\Component\DependencyInjection\ContainerInterface or Symfony\Component\Routing\RouterInterface as first argument.', __CLASS__));
37+
}
3538
}
3639

3740
/**
@@ -41,6 +44,10 @@ public function __construct(RouterInterface $router)
4144
*/
4245
public function warmUp($cacheDir)
4346
{
47+
if (null === $this->router) {
48+
$this->router = $this->container->get('router');
49+
}
50+
4451
if ($this->router instanceof WarmableInterface) {
4552
$this->router->warmUp($cacheDir);
4653
}

‎src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TranslationsCacheWarmer.php

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

1212
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
1313

14+
use Symfony\Component\DependencyInjection\ContainerInterface;
1415
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
1516
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
1617
use Symfony\Component\Translation\TranslatorInterface;
@@ -22,18 +23,29 @@
2223
*/
2324
class TranslationsCacheWarmer implements CacheWarmerInterface
2425
{
26+
private $container;
2527
private $translator;
2628

27-
public function __construct(TranslatorInterface $translator)
29+
public function __construct($container)
2830
{
29-
$this->translator = $translator;
31+
if ($container instanceof ContainerInterface) {
32+
$this->container = $container;
33+
} elseif ($container instanceof TranslatorInterface) {
34+
$this->translator = $container;
35+
} else {
36+
throw new \InvalidArgumentException(sprintf('%s only accepts instance of Symfony\Component\DependencyInjection\ContainerInterface or Symfony\Component\Translation\TranslatorInterface as first argument.', __CLASS__));
37+
}
3038
}
3139

3240
/**
3341
* {@inheritdoc}
3442
*/
3543
public function warmUp($cacheDir)
3644
{
45+
if (null === $this->translator) {
46+
$this->translator = $this->container->get('translator');
47+
}
48+
3749
if ($this->translator instanceof WarmableInterface) {
3850
$this->translator->warmUp($cacheDir);
3951
}

‎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 Symfony\Component\DependencyInjection\ContainerInterface or Twig_environment as first argument.', __CLASS__));
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.