Skip to content

Commit c68fcbe

Browse files
barryvdhnmalevanec
authored andcommitted
Ensure DeploymentConfig Reader always returns an array Throw exception on invalid config
1 parent c166940 commit c68fcbe

File tree

1 file changed

+10
-1
lines changed
  • lib/internal/Magento/Framework/App/DeploymentConfig

1 file changed

+10
-1
lines changed

lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
use Magento\Framework\App\Filesystem\DirectoryList;
1010
use Magento\Framework\Config\File\ConfigFilePool;
1111
use Magento\Framework\Exception\FileSystemException;
12+
use Magento\Framework\Exception\RuntimeException;
1213
use Magento\Framework\Filesystem\DriverPool;
14+
use Magento\Framework\Phrase;
1315

1416
/**
1517
* Deployment configuration reader.
@@ -87,6 +89,7 @@ public function getFiles()
8789
* @param string $fileKey The file key (deprecated)
8890
* @return array
8991
* @throws FileSystemException If file can not be read
92+
* @throws RuntimeException If file is invalid
9093
* @throws \Exception If file key is not correct
9194
* @see FileReader
9295
*/
@@ -99,6 +102,9 @@ public function load($fileKey = null)
99102
$filePath = $path . '/' . $this->configFilePool->getPath($fileKey);
100103
if ($fileDriver->isExists($filePath)) {
101104
$result = include $filePath;
105+
if (!is_array($result)) {
106+
throw new RuntimeException(new Phrase("Invalid configuration file: '%1'", [$filePath]));
107+
}
102108
}
103109
} else {
104110
$configFiles = $this->configFilePool->getPaths();
@@ -108,11 +114,14 @@ public function load($fileKey = null)
108114
$configFile = $path . '/' . $this->configFilePool->getPath($fileKey);
109115
if ($fileDriver->isExists($configFile)) {
110116
$fileData = include $configFile;
117+
if (!is_array($fileData)) {
118+
throw new RuntimeException(new Phrase("Invalid configuration file: '%1'", [$configFile]));
119+
}
111120
} else {
112121
continue;
113122
}
114123
$allFilesData[$configFile] = $fileData;
115-
if (is_array($fileData) && count($fileData) > 0) {
124+
if ($fileData) {
116125
$result = array_replace_recursive($result, $fileData);
117126
}
118127
}

0 commit comments

Comments
 (0)