/** * Loads the configuration file * * @param string $fileKey * @return array * @throws \Exception */ public function load($fileKey = null) { $path = $this->dirList->getPath(DirectoryList::CONFIG); $fileDriver = $this->driverPool->getDriver(DriverPool::FILE); $result = []; if ($fileKey) { $filePath = $path . '/' . $this->configFilePool->getPath($fileKey); if ($fileDriver->isExists($filePath)) { $result = (include $filePath); } } else { $configFiles = $this->configFilePool->getPaths(); $allFilesData = []; $result = []; foreach (array_keys($configFiles) as $fileKey) { $configFile = $path . '/' . $this->configFilePool->getPath($fileKey); if ($fileDriver->isExists($configFile)) { $fileData = (include $configFile); } else { continue; } $allFilesData[$configFile] = $fileData; if (!empty($fileData)) { $intersection = array_intersect_key($result, $fileData); if (!empty($intersection)) { $displayMessage = $this->findFilesWithKeys(array_keys($intersection), $allFilesData); throw new \Exception("Key collision! The following keys occur in multiple config files:" . PHP_EOL . $displayMessage); } $result = array_merge($result, $fileData); } } } return $result ?: []; }
/** * Loads the configuration file * * @param string $fileKey * @return array * @throws \Exception */ public function load($fileKey = null) { $path = $this->dirList->getPath(DirectoryList::CONFIG); if ($fileKey) { $result = @(include $path . '/' . $this->configFilePool->getPath($fileKey)); } else { $configFiles = $this->configFilePool->getPaths(); $result = []; foreach (array_keys($configFiles) as $fileKey) { $configFile = $path . '/' . $this->configFilePool->getPath($fileKey); $fileData = @(include $configFile); if (!empty($fileData)) { $intersection = array_intersect_key($result, $fileData); if (!empty($intersection)) { $displayList = ''; foreach (array_keys($intersection) as $key) { $displayList .= $key . PHP_EOL; } throw new \Exception("Key collision! The following keys occur in multiple config files:" . PHP_EOL . $displayList); } $result = array_merge($result, $fileData); } } } return $result ?: []; }
/** * Retrieve cache states (enabled/disabled) information * * Access configuration file directly as it is not possible to re-include modified file under HHVM * @link https://github.com/facebook/hhvm/issues/1447 * * @return array * @SuppressWarnings(PHPMD.EvalExpression) */ protected function getCacheStates() { $configFilePool = new ConfigFilePool(); $configPath = Bootstrap::getInstance()->getAppTempDir() . '/' . DirectoryList::CONFIG . '/' . $configFilePool->getPath($configFilePool::APP_ENV); $configData = eval(str_replace('<?php', '', file_get_contents($configPath))); return $configData[State::CACHE_KEY]; }
/** * Returns path to env.php file * * @return string * @throws \Exception */ private function getEnvPath() { $deploymentConfig = $this->directoryList->getPath(DirectoryList::CONFIG); $configPool = new ConfigFilePool(); $envPath = $deploymentConfig . '/' . $configPool->getPath(ConfigFilePool::APP_ENV); return $envPath; }
/** * @expectedException \Exception * @expectedExceptionMessage File config key does not exist. */ public function testGetPathException() { $fileKey = 'not_existing'; $this->configFilePool->getPath($fileKey); }