Skip to content

Commit

Permalink
support array of file path
Browse files Browse the repository at this point in the history
  • Loading branch information
zarv1k committed May 29, 2016
1 parent e341b63 commit 5a7a1c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
24 changes: 17 additions & 7 deletions components/Params.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,27 @@ protected function loadParams()
* @return array
* @throws InvalidConfigException
*/
protected function getFileParams()
public function getFileParams()
{
if (is_null($this->getFilePath())) {
return [];
}

$file = \Yii::getAlias($this->getFilePath());
if (!is_file($file)) {
throw new InvalidConfigException("Params file {$file} not found");
$fileParams = [];
$filePaths = $this->getFilePath();
if (!is_array($filePaths)) {
$filePaths = [$filePaths];
}
return require($file);

foreach ($filePaths as $filePath) {
$file = \Yii::getAlias($filePath);
if (!is_file($file)) {
throw new InvalidConfigException("Params file {$file} not found");
}
ArrayHelper::merge($fileParams, require($file));
}

return $fileParams;
}

/**
Expand Down Expand Up @@ -259,15 +269,15 @@ public function setDb($db)
}

/**
* @return array
* @return string|array
*/
public function getFilePath()
{
return $this->_filePath;
}

/**
* @param string $filePath
* @param string|attay $filePath
*/
public function setFilePath($filePath)
{
Expand Down
3 changes: 1 addition & 2 deletions modules/params/controllers/ManageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class ManageController extends Controller
public function actionIndex()
{
// prepare file params data provider
$filePath = \Yii::getAlias(\Yii::$app->params->getFilePath());
$fileParams = is_file($filePath) ? require($filePath) : [];
$fileParams = \Yii::$app->params->getFileParams();

$fileParamKeys = array_keys($fileParams);
$fileParamsArray = array_map(
Expand Down

0 comments on commit 5a7a1c9

Please sign in to comment.