Skip to content

Commit 3a7e223

Browse files
committed
Merge branch '4.4' into 5.1
* 4.4: [FrameworkBundle] generate preload.php in src/ to make opcache.preload predictable
2 parents d5c5257 + 64342e6 commit 3a7e223

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

Command/CacheClearCommand.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
175175
}
176176
}
177177

178+
$kernelDir = \dirname((new \ReflectionObject($kernel))->getFileName());
179+
$preloadFile = $fs->makePathRelative(\dirname($containerFile, 2), $kernelDir);
180+
$preloadFile .= substr_replace(basename($containerFile), '.preload', -4, 0);
181+
$preloadFile = var_export('/'.$preloadFile, true);
182+
@file_put_contents($kernelDir.'/preload.php', <<<EOPHP
183+
<?php
184+
185+
if (file_exists(__DIR__.$preloadFile)) {
186+
require __DIR__.$preloadFile;
187+
}
188+
189+
EOPHP
190+
);
191+
178192
if ($output->isVerbose()) {
179193
$io->comment('Finished');
180194
}

Tests/Command/CacheClearCommand/CacheClearCommandTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ protected function setUp(): void
3838
protected function tearDown(): void
3939
{
4040
$this->fs->remove($this->kernel->getProjectDir());
41+
$this->fs->remove(__DIR__.'/Fixture/preload.php');
4142
}
4243

4344
public function testCacheIsFreshAfterCacheClearedWithWarmup()
@@ -82,5 +83,7 @@ public function testCacheIsFreshAfterCacheClearedWithWarmup()
8283
$containerRef = new \ReflectionClass(require $containerFile);
8384
$containerFile = str_replace('tes_'.\DIRECTORY_SEPARATOR, 'test'.\DIRECTORY_SEPARATOR, $containerRef->getFileName());
8485
$this->assertMatchesRegularExpression(sprintf('/\'kernel.container_class\'\s*=>\s*\'%s\'/', $containerClass), file_get_contents($containerFile), 'kernel.container_class is properly set on the dumped container');
86+
87+
$this->assertFileEquals(__DIR__.'/Fixture/preload.php.expected', __DIR__.'/Fixture/preload.php');
8588
}
8689
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
if (file_exists(__DIR__.'/test/var/cache/test/FixtureSymfony_Bundle_FrameworkBundle_Tests_Command_CacheClearCommand_Fixture_TestAppKernelTestDebugContainer.preload.php')) {
4+
require __DIR__.'/test/var/cache/test/FixtureSymfony_Bundle_FrameworkBundle_Tests_Command_CacheClearCommand_Fixture_TestAppKernelTestDebugContainer.preload.php';
5+
}

0 commit comments

Comments
 (0)