Skip to content

Commit df50972

Browse files
committed
[FrameworkBundle] Provide $buildDir when running CacheWarmer to build read-only resources
Signed-off-by: Quentin Devos <4972091+Okhoshi@users.noreply.github.com>
1 parent 595c3c7 commit df50972

File tree

5 files changed

+28
-6
lines changed

5 files changed

+28
-6
lines changed

src/Symfony/Bundle/FrameworkBundle/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
---

src/Symfony/Bundle/FrameworkBundle/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();

src/Symfony/Bundle/FrameworkBundle/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);

src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7474

7575
$preload = $this->cacheWarmer->warmUp($cacheDir);
7676

77-
if ($preload && file_exists($preloadFile = $cacheDir.'/'.$kernel->getContainer()->getParameter('kernel.container_class').'.preload.php')) {
77+
$buildDir = $kernel->getContainer()->getParameter('kernel.build_dir');
78+
if ($preload && $cacheDir === $buildDir && file_exists($preloadFile = $buildDir.'/'.$kernel->getContainer()->getParameter('kernel.container_class').'.preload.php')) {
7879
Preloader::append($preloadFile, $preload);
7980
}
8081

src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/ConfigBuilderCacheWarmerTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
1616
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1717
use Symfony\Component\Config\Loader\LoaderInterface;
18+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1819
use Symfony\Component\DependencyInjection\ContainerBuilder;
1920
use Symfony\Component\Filesystem\Filesystem;
2021
use Symfony\Component\HttpKernel\Kernel;
@@ -39,7 +40,7 @@ protected function tearDown(): void
3940

4041
public function testBuildDirIsUsedAsConfigBuilderOutputDir()
4142
{
42-
$kernel = new class($this->varDir) extends Kernel {
43+
$kernel = new class($this->varDir) extends Kernel implements CompilerPassInterface {
4344
private $varDir;
4445

4546
public function __construct(string $varDir)
@@ -75,12 +76,25 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
7576
]);
7677
});
7778
}
79+
80+
public function process(ContainerBuilder $container): void
81+
{
82+
$container->removeDefinition('config_builder.warmer');
83+
}
7884
};
7985
$kernel->boot();
8086

87+
self::assertDirectoryDoesNotExist($kernel->getBuildDir().'/Symfony');
88+
self::assertDirectoryDoesNotExist($kernel->getCacheDir().'/Symfony');
89+
8190
$warmer = new ConfigBuilderCacheWarmer($kernel);
8291
$warmer->warmUp($kernel->getCacheDir());
8392

93+
self::assertDirectoryDoesNotExist($kernel->getBuildDir().'/Symfony');
94+
self::assertDirectoryDoesNotExist($kernel->getCacheDir().'/Symfony');
95+
96+
$warmer->warmUp($kernel->getCacheDir(), $kernel->getBuildDir());
97+
8498
self::assertDirectoryExists($kernel->getBuildDir().'/Symfony');
8599
self::assertDirectoryDoesNotExist($kernel->getCacheDir().'/Symfony');
86100
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy