Skip to content

Commit 38e4119

Browse files
okhoshinicolas-grekas
authored andcommitted
[FrameworkBundle][HttpKernel] Introduce $buildDir argument to WarmableInterface::warmup to warm read-only artefacts in build_dir
1 parent 6499aed commit 38e4119

15 files changed

+60
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ CHANGELOG
3232
* Add `--exclude` option to the `cache:pool:clear` command
3333
* Add parameters deprecations to the output of `debug:container` command
3434
* Change `framework.asset_mapper.importmap_polyfill` from a URL to the name of an item in the importmap
35+
* Provide `$buildDir` when running `CacheWarmer` to build read-only resources
3536

3637
6.3
3738
---

CacheWarmer/AbstractPhpFileCacheWarmer.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ public function isOptional(): bool
3535
}
3636

3737
/**
38-
* @return string[] A list of classes to preload on PHP 7.4+
38+
* @param string|null $buildDir
3939
*/
40-
public function warmUp(string $cacheDir): array
40+
public function warmUp(string $cacheDir /* , string $buildDir = null */): array
4141
{
42+
$buildDir = 1 < \func_num_args() ? func_get_arg(1) : null;
4243
$arrayAdapter = new ArrayAdapter();
4344

4445
spl_autoload_register([ClassExistenceResource::class, 'throwOnRequiredClass']);
4546
try {
46-
if (!$this->doWarmUp($cacheDir, $arrayAdapter)) {
47+
if (!$this->doWarmUp($cacheDir, $arrayAdapter, $buildDir)) {
4748
return [];
4849
}
4950
} finally {
@@ -78,7 +79,9 @@ final protected function ignoreAutoloadException(string $class, \Exception $exce
7879
}
7980

8081
/**
82+
* @param string|null $buildDir
83+
*
8184
* @return bool false if there is nothing to warm-up
8285
*/
83-
abstract protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter): bool;
86+
abstract protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter /* , string $buildDir = null */): bool;
8487
}

CacheWarmer/AnnotationsCacheWarmer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ public function __construct(
4444
parent::__construct($phpArrayFile);
4545
}
4646

47-
protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter): bool
47+
/**
48+
* @param string|null $buildDir
49+
*/
50+
protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter /* , string $buildDir = null */): bool
4851
{
4952
$annotatedClassPatterns = $cacheDir.'/annotations.map';
5053

CacheWarmer/CachePoolClearerCacheWarmer.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ public function __construct(Psr6CacheClearer $poolClearer, array $pools = [])
3737
$this->pools = $pools;
3838
}
3939

40-
/**
41-
* @return string[]
42-
*/
43-
public function warmUp(string $cacheDirectory): array
40+
public function warmUp(string $cacheDir, string $buildDir = null): array
4441
{
4542
foreach ($this->pools as $pool) {
4643
if ($this->poolClearer->hasPool($pool)) {

CacheWarmer/ConfigBuilderCacheWarmer.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,17 @@ public function __construct(KernelInterface $kernel, LoggerInterface $logger = n
3838
}
3939

4040
/**
41-
* @return string[]
41+
* @param string|null $buildDir
4242
*/
43-
public function warmUp(string $cacheDir): array
43+
public function warmUp(string $cacheDir /* , string $buildDir = null */): array
4444
{
45-
$generator = new ConfigBuilderGenerator($this->kernel->getBuildDir());
45+
$buildDir = 1 < \func_num_args() ? func_get_arg(1) : null;
46+
47+
if (!$buildDir) {
48+
return [];
49+
}
50+
51+
$generator = new ConfigBuilderGenerator($buildDir);
4652

4753
foreach ($this->kernel->getBundles() as $bundle) {
4854
$extension = $bundle->getContainerExtension();

CacheWarmer/RouterCacheWarmer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ public function __construct(ContainerInterface $container)
3434
$this->container = $container;
3535
}
3636

37-
public function warmUp(string $cacheDir): array
37+
public function warmUp(string $cacheDir, string $buildDir = null): array
3838
{
3939
$router = $this->container->get('router');
4040

4141
if ($router instanceof WarmableInterface) {
42-
return (array) $router->warmUp($cacheDir);
42+
return (array) $router->warmUp($cacheDir, $buildDir);
4343
}
4444

4545
throw new \LogicException(sprintf('The router "%s" cannot be warmed up because it does not implement "%s".', get_debug_type($router), WarmableInterface::class));

CacheWarmer/SerializerCacheWarmer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ public function __construct(array $loaders, string $phpArrayFile)
3939
$this->loaders = $loaders;
4040
}
4141

42-
protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter): bool
42+
/**
43+
* @param string|null $buildDir
44+
*/
45+
protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter /* , string $buildDir = null */): bool
4346
{
4447
if (!$this->loaders) {
4548
return true;

CacheWarmer/TranslationsCacheWarmer.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@ public function __construct(ContainerInterface $container)
3434
}
3535

3636
/**
37-
* @return string[]
37+
* @param string|null $buildDir
3838
*/
39-
public function warmUp(string $cacheDir): array
39+
public function warmUp(string $cacheDir /* , string $buildDir = null */): array
4040
{
4141
$this->translator ??= $this->container->get('translator');
4242

4343
if ($this->translator instanceof WarmableInterface) {
44-
return (array) $this->translator->warmUp($cacheDir);
44+
$buildDir = 1 < \func_num_args() ? func_get_arg(1) : null;
45+
46+
return (array) $this->translator->warmUp($cacheDir, $buildDir);
4547
}
4648

4749
return [];

CacheWarmer/ValidatorCacheWarmer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ public function __construct(ValidatorBuilder $validatorBuilder, string $phpArray
3939
$this->validatorBuilder = $validatorBuilder;
4040
}
4141

42-
protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter): bool
42+
/**
43+
* @param string|null $buildDir
44+
*/
45+
protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter /* , string $buildDir = null */): bool
4346
{
4447
$loaders = $this->validatorBuilder->getLoaders();
4548
$metadataFactory = new LazyLoadingMetadataFactory(new LoaderChain($loaders), $arrayAdapter);

Command/CacheClearCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ private function warmupOptionals(string $cacheDir, string $warmupDir, SymfonySty
245245
$warmer = $kernel->getContainer()->get('cache_warmer');
246246
// non optional warmers already ran during container compilation
247247
$warmer->enableOnlyOptionalWarmers();
248-
$preload = (array) $warmer->warmUp($cacheDir, $io);
248+
$preload = (array) $warmer->warmUp($cacheDir, $warmupDir, $io);
249249

250250
if ($preload && file_exists($preloadFile = $warmupDir.'/'.$kernel->getContainer()->getParameter('kernel.container_class').'.preload.php')) {
251251
Preloader::append($preloadFile, $preload);

0 commit comments

Comments
 (0)