Skip to content

Commit 40bbc08

Browse files
[HttpKernel] make kernels implementing WarmableInterface be part of the cache warmup stage
1 parent 4170346 commit 40bbc08

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/Symfony/Component/HttpKernel/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* made `WarmableInterface::warmUp()` return a list of classes or files to preload on PHP 7.4+;
88
not returning an array is deprecated
9+
* made kernels implementing `WarmableInterface` be part of the cache warmup stage
910
* deprecated support for `service:action` syntax to reference controllers, use `serviceOrFqcn::method` instead
1011
* allowed using public aliases to reference controllers
1112
* added session usage reporting when the `_stateless` attribute of the request is set to `true`

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use Symfony\Component\HttpFoundation\Request;
3636
use Symfony\Component\HttpFoundation\Response;
3737
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
38+
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
3839
use Symfony\Component\HttpKernel\Config\FileLocator;
3940
use Symfony\Component\HttpKernel\DependencyInjection\AddAnnotatedClassesToCachePass;
4041
use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
@@ -563,12 +564,14 @@ protected function initializeContainer()
563564
touch($oldContainerDir.'.legacy');
564565
}
565566

567+
$preload = $this instanceof WarmableInterface ? (array) $this->warmUp($this->container->getParameter('kernel.cache_dir')) : [];
568+
566569
if ($this->container->has('cache_warmer')) {
567-
$preload = (array) $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir'));
570+
$preload = array_merge($preload, (array) $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir')));
571+
}
568572

569-
if (method_exists(Preloader::class, 'append') && file_exists($preloadFile = $cacheDir.'/'.$class.'.preload.php')) {
570-
Preloader::append($preloadFile, $preload);
571-
}
573+
if ($preload && method_exists(Preloader::class, 'append') && file_exists($preloadFile = $cacheDir.'/'.$class.'.preload.php')) {
574+
Preloader::append($preloadFile, $preload);
572575
}
573576
}
574577

0 commit comments

Comments
 (0)