Skip to content

Commit

Permalink
+ uniqueConfig to remove duplicates from arrays in configs
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Nov 19, 2015
1 parent 2fde5fa commit e5f0713
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/goals/FileGoal.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public function actionLoad()

public function actionSave()
{
$this->_items = Helper::uniqueConfig($this->_items);
return $this->getFile()->save($this);
}
}
17 changes: 17 additions & 0 deletions src/helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,21 @@ public static function titleize($str, $ucAll = true)
{
return Inflector::titleize(strtr($str, '-', ' '), $ucAll);
}

/**
* Recursively removes duplicate values from non-associative arrays
*/
public static function uniqueConfig($array)
{
$suitable = true;
foreach ($array as $k => &$v) {
if (is_array($v)) {
$v = self::uniqueConfig($v);
$suitable = false;
} elseif (!is_int($k)) {
$suitable = false;
}
}
return $suitable ? array_unique($array) : $array;
}
}

0 comments on commit e5f0713

Please sign in to comment.