Skip to content

Commit 595c3c7

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

File tree

7 files changed

+63
-12
lines changed

7 files changed

+63
-12
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8109,11 +8109,11 @@ diff --git a/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerInterface.p
81098109
diff --git a/src/Symfony/Component/HttpKernel/CacheWarmer/WarmableInterface.php b/src/Symfony/Component/HttpKernel/CacheWarmer/WarmableInterface.php
81108110
--- a/src/Symfony/Component/HttpKernel/CacheWarmer/WarmableInterface.php
81118111
+++ b/src/Symfony/Component/HttpKernel/CacheWarmer/WarmableInterface.php
8112-
@@ -24,4 +24,4 @@ interface WarmableInterface
8112+
@@ -27,4 +27,4 @@ interface WarmableInterface
81138113
* @return string[] A list of classes or files to preload on PHP 7.4+
81148114
*/
8115-
- public function warmUp(string $cacheDir);
8116-
+ public function warmUp(string $cacheDir): array;
8115+
- public function warmUp(string $cacheDir /* , string $buildDir = null */);
8116+
+ public function warmUp(string $cacheDir /* , string $buildDir = null */): array;
81178117
}
81188118
diff --git a/src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php
81198119
--- 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
@@ -15,6 +15,7 @@ CHANGELOG
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
1717
* Deprecate `FileLinkFormatter`, use `FileLinkFormatter` from the ErrorHandler component instead
18+
* Add argument `$buildDir` to `WarmableInterface`
1819

1920
6.3
2021
---

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

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

51-
public function warmUp(string $cacheDir, SymfonyStyle $io = null): array
51+
/**
52+
* @param string|null $buildDir
53+
*/
54+
public function warmUp(string $cacheDir, string|SymfonyStyle $buildDir = null, SymfonyStyle $io = null): array
5255
{
56+
if ($buildDir instanceof SymfonyStyle) {
57+
trigger_deprecation('symfony/http-kernel', '6.4', 'Passing a "%s" as second argument of "%s()" is deprecated, pass it as third argument instead, after the build directory.', SymfonyStyle::class, __METHOD__);
58+
$io = $buildDir;
59+
$buildDir = null;
60+
}
61+
5362
if ($collectDeprecations = $this->debug && !\defined('PHPUNIT_COMPOSER_INSTALL')) {
5463
$collectedLogs = [];
5564
$previousHandler = set_error_handler(function ($type, $message, $file, $line) use (&$collectedLogs, &$previousHandler) {
@@ -96,8 +105,8 @@ public function warmUp(string $cacheDir, SymfonyStyle $io = null): array
96105
}
97106

98107
$start = microtime(true);
99-
foreach ((array) $warmer->warmUp($cacheDir) as $item) {
100-
if (is_dir($item) || (str_starts_with($item, \dirname($cacheDir)) && !is_file($item))) {
108+
foreach ((array) $warmer->warmUp($cacheDir, $buildDir) as $item) {
109+
if (is_dir($item) || (str_starts_with($item, \dirname($cacheDir)) && !is_file($item)) || ($buildDir && str_starts_with($item, \dirname($buildDir)) && !is_file($item))) {
101110
throw new \LogicException(sprintf('"%s::warmUp()" should return a list of files or classes but "%s" is none of them.', $warmer::class, $item));
102111
}
103112
$preload[] = $item;

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 $cacheDir Where warm-up artifacts should be stored
25+
* @param string|null $buildDir Where read-only artifacts should go; null when called after compile-time
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)
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