Skip to content

Commit

Permalink
Do not load config from empty cache file
Browse files Browse the repository at this point in the history
This change solves a fatal error that I've been encountering, whenever
the cache file is present, but empty:

Uncaught TypeError: Cannot assign int to property
Laminas\ConfigAggregator\ConfigAggregator::$config of type array

So, this change returns false if the config file is present but empty.

Signed-off-by: Matthew Setter <[email protected]>
  • Loading branch information
settermjd committed Jun 19, 2024
1 parent 49df885 commit f21e955
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ConfigAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ private function loadConfigFromCache(null|string $cachedConfigFile): bool
return false;
}

if (filesize($cachedConfigFile) === 0) {

Check failure on line 260 in src/ConfigAggregator.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Function filesize() should not be referenced via a fallback global name, but via a use statement.
return false;
}

$this->config = require $cachedConfigFile;
return true;
}
Expand Down
8 changes: 8 additions & 0 deletions test/ConfigAggregatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ public function testConfigAggregatorSetsHandlesUnwritableCache(): void
self::assertFileDoesNotExist($this->cacheFile);
}

public function testConfigAggregatorDoesNotLoadConfigFromCacheIfCacheFileIsEmpty(): void
{
file_put_contents($this->cacheFile, '');
$aggregator = new ConfigAggregator([], $this->cacheFile);

self::assertEmpty($aggregator->getMergedConfig());
}

public function testConfigAggregatorCanLoadConfigFromCache(): void
{
$expected = [
Expand Down

0 comments on commit f21e955

Please sign in to comment.