Skip to content

Commit

Permalink
Merge pull request #92 from grasmash/issue-38-array-to-string
Browse files Browse the repository at this point in the history
Fixes #38: Multiple packages using the same patch throws an array to string exception.
  • Loading branch information
cweagans committed Feb 16, 2017
2 parents e395c7c + 56be0c2 commit 1107991
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/Patches.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function gatherPatches(PackageEvent $event) {
}
}
}
$this->patches = array_merge_recursive($this->patches, $extra['patches']);
$this->patches = $this->arrayMergeRecursiveDistinct($this->patches, $extra['patches']);
}
// Unset installed patches for this package
if(isset($this->installedPatches[$package->getName()])) {
Expand Down Expand Up @@ -456,4 +456,36 @@ protected function executeCommand($cmd) {
}
return ($this->executor->execute($command, $output) == 0);
}

/**
* Recursively merge arrays without changing data types of values.
*
* Does not change the data types of the values in the arrays. Matching keys'
* values in the second array overwrite those in the first array, as is the
* case with array_merge.
*
* @param array $array1
* The first array.
* @param array $array2
* The second array.
* @return array
* The merged array.
*
* @see http://php.net/manual/en/function.array-merge-recursive.php#92195
*/
protected function arrayMergeRecursiveDistinct(array $array1, array $array2) {
$merged = $array1;

foreach ($array2 as $key => &$value) {
if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
$merged[$key] = $this->arrayMergeRecursiveDistinct($merged[$key], $value);
}
else {
$merged[$key] = $value;
}
}

return $merged;
}

}

0 comments on commit 1107991

Please sign in to comment.