8000 [HttpKernel] Add argument `$buildDir` to `WarmableInterface` · symfony/symfony@00d487f · GitHub
[go: up one dir, main page]

Skip to content

Commit 00d487f

Browse files
committed
[HttpKernel] Add argument $buildDir to WarmableInterface
Signed-off-by: Quentin Devos <4972091+Okhoshi@users.noreply.github.com>
1 parent f9a64ee commit 00d487f

File tree

7 files changed

+53
-11
lines changed

7 files changed

+53
-11
lines changed

.github/expected-missing-return-types.diff

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8092,11 +8092,11 @@ diff --git a/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerInterface.p
80928092
diff --git a/src/Symfony/Component/HttpKernel/CacheWarmer/WarmableInterface.php b/src/Symfony/Component/HttpKernel/CacheWarmer/WarmableInterface.php
80938093
--- a/src/Symfony/Component/HttpKernel/CacheWarmer/WarmableInterface.php
80948094
+++ b/src/Symfony/Component/HttpKernel/CacheWarmer/WarmableInterface.php
8095-
@@ -24,4 +24,4 @@ interface WarmableInterface
8095+
@@ -27,4 +27,4 @@ interface WarmableInterface
80968096
* @return string[] A list of classes or files to preload on PHP 7.4+
80978097
*/
8098-
- public function warmUp(string $cacheDir);
8099-
+ public function warmUp(string $cacheDir): array;
8098+
- public function warmUp(string $cacheDir /* , string $buildDir = null */);
8099+
+ public function warmUp(string $cacheDir /* , string $buildDir = null */): array;
81008100
}
81018101
diff --git a/src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php
81028102
--- a/src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php

src/Symfony/Component/HttpKernel/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ CHANGELOG
1414
* Deprecate `Kernel::stripComments()`
1515
* Support the `!` character at the beginning of a string as a negation operator in the url filter of the profiler
1616
* Deprecate `UriSigner`, use `UriSigner` from the HttpFoundation component instead
17+
* Add argument `$buildDir` to `WarmableInterface`
1718

1819
6.3
1920
---

src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function enableOnlyOptionalWarmers(): void
4848
$this->onlyOptionalsEnabled = $this->optionalsEnabled = true;
4949
}
5050

51-
public function warmUp(string $cacheDir, SymfonyStyle $io = null): array
51+
public function warmUp(string $cacheDir, string $buildDir = null, SymfonyStyle $io = null): array
5252
{
5353
if ($collectDeprecations = $this->debug && !\defined('PHPUNIT_COMPOSER_INSTALL')) {
5454
$collectedLogs = [];
@@ -96,7 +96,7 @@ public function warmUp(string $cacheDir, SymfonyStyle $io = null): array
9696
}
9797

9898
$start = microtime(true);
99-
foreach ((array) $warmer->warmUp($cacheDir) as $item) {
99+
foreach ((array) $warmer->warmUp($cacheDir, null === $buildDir || $warmer->isOptional() ? null : $buildDir) as $item) {
100100
if (is_dir($item) || (str_starts_with($item, \dirname($cacheDir)) && !is_file($item))) {
101101
throw new \LogicException(sprintf('"%s::warmUp()" should return a list of files or classes but "%s" is none of them.', $warmer::class, $item));
102102
}

src/Symfony/Component/HttpKernel/CacheWarmer/WarmableInterface.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ interface WarmableInterface
2121
/**
2222
* Warms up the cache.
2323
*
24+
* @param string|null $buildDir directory to put generated source code that can be marked as read-only at runtime.
25+
* The directory is not provided when only cache_dir should be warmed up.
26+
*
2427
* @return string[] A list of classes or files to preload on PHP 7.4+
2528
*/
26-
public function warmUp(string $cacheDir);
29+
public function warmUp(string $cacheDir /* , string $buildDir = null */);
2730
}

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,10 +539,10 @@ protected function initializeContainer()
539539
touch($oldContainerDir.'.legacy');
540540
}
541541

542-
$preload = $this instanceof WarmableInterface ? (array) $this->warmUp($this->container->getParameter('kernel.cache_dir')) : [];
542+
$preload = $this instanceof WarmableInterface ? (array) $this->warmUp($this->container->getParameter('kernel.cache_dir'), $buildDir) : [];
543543

544544
if ($this->container->has('cache_warmer')) {
545-
$preload = array_merge($preload, (array) $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir')));
545+
$preload = array_merge($preload, (array) $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir'), $buildDir));
546546
}
547547

548548
if ($preload && file_exists($preloadFile = $buildDir.'/'.$class.'.preload.php')) {

src/Symfony/Component/HttpKernel/Tests/CacheWarmer/CacheWarmerAggregateTest.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,40 @@ public function testWarmupChecksInvalidFiles()
9393
$aggregate->warmUp(__DIR__);
9494
}
9595

96+
public function testWarmupPassBuildDir()
97+
{
98+
$warmer = $this->createMock(CacheWarmerInterface::class);
99+
$warmer
100+
->expects($this->once())
101+
->method('isOptional')
102+
->willReturn(false);
103+
$warmer
104+
->expects($this->once())
105+
->method('warmUp')
106+
->with('cache_dir', 'build_dir');
107+
108+
$aggregate = new CacheWarmerAggregate([$warmer]);
109+
$aggregate->enableOptionalWarmers();
110+
$aggregate->warmUp('cache_dir', 'build_dir');
111+
}
112+
113+
public function testWarmupOnOptionalWarmerDoNotPassBuildDir()
114+
{
115+
$warmer = $this->createMock(CacheWarmerInterface::class);
116+
$warmer
117+
->expects($this->once())
118+
->method('isOptional')
119+
->willReturn(true);
120+
$warmer
121+
->expects($this->once())
122+
->method('warmUp')
123+
->with('cache_dir', null);
124+
125+
$aggregate = new CacheWarmerAggregate([$warmer]);
126+
$aggregate->enableOptionalWarmers();
127+
$aggregate->warmUp('cache_dir', 'build_dir');
128+
}
129+
96130
public function testWarmupWhenDebugDisplaysWarmupDuration()
97131
{
98132
$warmer = $this->createMock(CacheWarmerInterface::class);
@@ -115,7 +149,7 @@ public function testWarmupWhenDebugDisplaysWarmupDuration()
115149
->method('warmUp');
116150

117151
$aggregate = new CacheWarmerAggregate([$warmer]);
118-
$aggregate->warmUp(__DIR__, $io);
152+
$aggregate->warmUp(__DIR__, null, $io);
119153
}
120154

121155
public function testWarmupWhenNotDebugDoesntDisplayWarmupDuration()
@@ -140,6 +174,6 @@ public function testWarmupWhenNotDebugDoesntDisplayWarmupDuration()
140174
->method('warmUp');
141175

142176
$aggregate = new CacheWarmerAggregate([$warmer]);
143-
$aggregate->warmUp(__DIR__, $io);
177+
$aggregate->warmUp(__DIR__, null, $io);
144178
}
145179
}

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ public function testWarmup()
562562
$kernel->boot();
563563

564564
$this->assertTrue($kernel->warmedUp);
565+
$this->assertSame($kernel->getBuildDir(), $kernel->warmedUpBuildDir);
565566
}
566567

567568
public function testServicesResetter()
@@ -756,6 +757,8 @@ class CustomProjectDirKernel extends Kernel implements WarmableInterface
756757
{
757758
public bool $warmedUp = false;
758759

760+
public ?string $warmedUpBuildDir = null;
761+
759762
public function __construct(
760763
private readonly ?\Closure $buildContainer = null,
761764
private readonly ?HttpKernelInterface $httpKernel = null,
@@ -778,9 +781,10 @@ public function getProjectDir(): string
778781
return __DIR__.'/Fixtures';
779782
}
780783

781-
public function warmUp(string $cacheDir): array
784+
public function warmUp(string $cacheDir, string $buildDir = null): array
782785
{
783786
$this->warmedUp = true;
787+
$this->warmedUpBuildDir = $buildDir;
784788

785789
return [];
786790
}

0 commit comments

Comments
 (0)
0