Skip to content

Commit f21e955

Browse files
committed
Do not load config from empty cache file
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 <matthew@matthewsetter.com>
1 parent 49df885 commit f21e955

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/ConfigAggregator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ private function loadConfigFromCache(null|string $cachedConfigFile): bool
257257
return false;
258258
}
259259

260+
if (filesize($cachedConfigFile) === 0) {
261+
return false;
262+
}
263+
260264
$this->config = require $cachedConfigFile;
261265
return true;
262266
}

test/ConfigAggregatorTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,14 @@ public function testConfigAggregatorSetsHandlesUnwritableCache(): void
230230
self::assertFileDoesNotExist($this->cacheFile);
231231
}
232232

233+
public function testConfigAggregatorDoesNotLoadConfigFromCacheIfCacheFileIsEmpty(): void
234+
{
235+
file_put_contents($this->cacheFile, '');
236+
$aggregator = new ConfigAggregator([], $this->cacheFile);
237+
238+
self::assertEmpty($aggregator->getMergedConfig());
239+
}
240+
233241
public function testConfigAggregatorCanLoadConfigFromCache(): void
234242
{
235243
$expected = [

0 commit comments

Comments
 (0)