schnittstabil/config_merge

Merge config arrays

2.0.0 2016-04-14 18:11 UTC

This package is auto-updated.

Last update: 2024-10-26 03:21:16 UTC


README

SensioLabsInsight

Merge config arrays

Install

$ composer require schnittstabil/config_merge

Usage

use function Schnittstabil\ConfigMerge\config_merge;

$target = json_decode(<<<'EOD'
{
    "files": ["src", "tests"],
    "opts": {
        "unicorns": 0,
        "leprechauns": 666
    }
}
EOD
);

$source = json_decode(<<<'EOD'
{
    "files": ["target"],
    "opts": {
        "unicorns": 42
    }
}
EOD
);

json_encode(config_merge($target, $source), JSON_PRETTY_PRINT);
/* =>
{
    "files": [
        "target"
    ],
    "opts": {
        "unicorns": 42,
        "leprechauns": 666
    }
}
*/

API

/**
 * Merge two configs.
 *
 * @param mixed $target       Target config
 * @param mixed $source       Source config
 * @param bool  $appendArrays if true use `array_merge`
 *
 * @return mixed The merged config
 */
function config_merge($target, $source, $appendArrays = false)

License

MIT © Michael Mayer