Skip to content

Commit

Permalink
Merge branch 'master' of github.com:CSBill/RequireJSBundle
Browse files Browse the repository at this point in the history
* 'master' of github.com:CSBill/RequireJSBundle:
  Copy arrayMergeRecursiveDistinct method form PhpUtils/ArrayUtil
  Update composer to allow Symfony 3
  • Loading branch information
pierredup committed Jul 25, 2016
2 parents 77afabb + fad310f commit e0f5618
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
35 changes: 32 additions & 3 deletions Provider/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

use Doctrine\Common\Cache\CacheProvider;

use Oro\Component\PhpUtils\ArrayUtil;

class Config
{
const REQUIREJS_CONFIG_CACHE_KEY = 'requirejs_config';
Expand Down Expand Up @@ -149,7 +147,7 @@ public function collectConfigs()
$reflection = new \ReflectionClass($bundle);
if (is_file($file = dirname($reflection->getFilename()) . '/Resources/config/requirejs.yml')) {
$requirejs = Yaml::parse(realpath($file));
$config = ArrayUtil::arrayMergeRecursiveDistinct($config, $requirejs);
$config = self::arrayMergeRecursiveDistinct($config, $requirejs);
}
}

Expand All @@ -158,4 +156,35 @@ public function collectConfigs()

return $this->collectedConfig;
}

/**
* Recursively merge arrays.
*
* Merge two arrays as array_merge_recursive do, but instead of converting values to arrays when keys are same
* replaces value from first array with value from second
*
* @param array $first
* @param array $second
*
* @return array
*/
public static function arrayMergeRecursiveDistinct(array $first, array $second)
{
foreach ($second as $idx => $value) {
if (is_integer($idx)) {
$first[] = $value;
} else {
if (!array_key_exists($idx, $first)) {
$first[$idx] = $value;
} else {
if (is_array($value)) {
$first[$idx] = self::arrayMergeRecursiveDistinct($first[$idx], $value);
} else {
$first[$idx] = $value;
}
}
}
}
return $first;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "MIT",
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.7.*"
"symfony/symfony": "^2.7|^3.0"
},
"autoload": {
"psr-0": { "Oro\\Bundle\\RequireJSBundle": "" }
Expand Down

0 comments on commit e0f5618

Please sign in to comment.