Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- Read the di.xml files through the runtime loader of Magento when the installation has no compiled metadata, so a developer-mode install serves requests.

## 0.2.0-rc5

- Use Credis when the PHP Redis extension is unavailable; phpredis remains the preferred transport when installed.
Expand Down
13 changes: 9 additions & 4 deletions src/FastBoot/Model/ObjectManager/AreaConfigLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use GraphCommerce\FastBootCache\Model\Release;
use Magento\Framework\App\Area;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\ObjectManager\ConfigLoader;
use Magento\Framework\App\ObjectManager\ConfigLoader\Compiled;
use Magento\Framework\ObjectManager\ConfigLoaderInterface;

Expand All @@ -17,7 +18,9 @@
* global one it already holds: 15 000 arguments replaced by themselves on
* every request. This loader hands the object manager only the entries the
* area changes, from a file under var/cache/fastboot/metadata that follows
* an immutable release identity (or the source hashes without one).
* an immutable release identity (or the source hashes without one). An
* installation without compiled metadata reads the di.xml files through the
* runtime loader of Magento.
*/
class AreaConfigLoader implements ConfigLoaderInterface
{
Expand All @@ -30,6 +33,7 @@ public function __construct(
private readonly DirectoryList $directoryList,
private readonly Feature $feature,
private readonly Release $release,
private readonly ConfigLoader $runtimeLoader,
) {
}

Expand All @@ -40,9 +44,10 @@ public function load($area, bool $rebuild = false)
}
$areaFile = Compiled::getFilePath($area);
$globalFile = Compiled::getFilePath(Area::AREA_GLOBAL);
if ($area === Area::AREA_GLOBAL || !is_file($areaFile) || !is_file($globalFile)
|| !$this->feature->on(self::SWITCH)
) {
if (!is_file($areaFile) || !is_file($globalFile)) {
return $this->loaded[$area] = $this->runtimeLoader->load($area);
}
if ($area === Area::AREA_GLOBAL || !$this->feature->on(self::SWITCH)) {
return $this->loaded[$area] = include $areaFile;
}
$release = $this->release->id();
Expand Down
23 changes: 22 additions & 1 deletion src/FastBoot/Test/Unit/Model/AreaConfigLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,33 @@
use GraphCommerce\FastBootCache\Model\Feature;
use GraphCommerce\FastBootCache\Model\Release;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\ObjectManager\ConfigLoader;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\TestCase;

class AreaConfigLoaderTest extends TestCase
{
#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testInstallationWithoutCompiledMetadataUsesTheRuntimeLoader(): void
{
$root = sys_get_temp_dir().'/fastboot-area-'.bin2hex(random_bytes(8));
define('BP', $root);
$calls = 0;
$runtime = $this->createStub(ConfigLoader::class);
$runtime->method('load')->willReturnCallback(static function (string $area) use (&$calls): array {
$calls++;
return ['arguments' => ['runtime' => $area]];
});
$feature = $this->createStub(Feature::class);
$feature->method('on')->willReturn(true);
$loader = new AreaConfigLoader($this->createStub(DirectoryList::class), $feature, $this->createStub(Release::class), $runtime);
self::assertSame(['arguments' => ['runtime' => 'graphql']], $loader->load('graphql'));
self::assertSame(['arguments' => ['runtime' => 'graphql']], $loader->load('graphql'));
self::assertSame(1, $calls);
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testCorruptArtifactsRepairAndPreparationRebuildsChangedMetadata(): void
Expand All @@ -34,7 +55,7 @@ public function testCorruptArtifactsRepairAndPreparationRebuildsChangedMetadata(
$feature->method('on')->willReturn(true);
$release = $this->createStub(Release::class);
$release->method('id')->willReturn('deployed-build');
$loader = fn () => new AreaConfigLoader($directory, $feature, $release);
$loader = fn () => new AreaConfigLoader($directory, $feature, $release, $this->createStub(ConfigLoader::class));
$expected = ['arguments' => ['changed' => ['x' => 2]]];
try {
self::assertSame($expected, $loader()->load('graphql'));
Expand Down