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:
  Don't pass the file name to Yaml::parse
  Updated service config to quote scalar values starting with @ and %
  Copy arrayMergeRecursiveDistinct method form PhpUtils/ArrayUtil
  Update composer to allow Symfony 3
  • Loading branch information
pierredup committed Jul 25, 2016
2 parents eed11ca + a05efa1 commit 2f0b4e0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 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(file_get_contents(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;
}
}
8 changes: 4 additions & 4 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ parameters:

services:
oro_requirejs.twig.requirejs_extension:
class: %oro_requirejs.twig.class%
class: '%oro_requirejs.twig.class%'
arguments:
- "@service_container"
- '@service_container'
tags:
- { name: twig.extension }

Expand All @@ -16,11 +16,11 @@ services:
- [setNamespace, [ 'oro_requirejs' ] ]

oro_requirejs_config_provider:
class: %oro_requirejs.provider.config.class%
class: '%oro_requirejs.provider.config.class%'
arguments:
- '@service_container'
- '@templating'
- OroRequireJSBundle::require_config.js.twig
- 'OroRequireJSBundle::require_config.js.twig'
calls:
- [ setCache, [ '@oro_requirejs.cache' ] ]
lazy: true
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 2f0b4e0

Please sign in to comment.