65fccf72abcba951c1f889bd425795822f63e42d
[yaffs-website] / vendor / consolidation / config / src / Util / ConfigMerge.php
1 <?php
2 namespace Consolidation\Config\Util;
3
4 /**
5  * Works like 'getWithFallback', but merges results from all applicable
6  * groups. Settings from most specific group take precedence.
7  */
8 class ConfigMerge extends ConfigGroup
9 {
10     /**
11      * @inheritdoc
12      */
13     public function get($key)
14     {
15         return $this->getWithMerge($key, $this->group, $this->prefix, $this->postfix);
16     }
17
18     /**
19      * Merge available configuration from each configuration group.
20      */
21     public function getWithMerge($key, $group, $prefix = '', $postfix = '.')
22     {
23         $configKey = "{$prefix}{$group}${postfix}{$key}";
24         $result = $this->config->get($configKey, []);
25         if (!is_array($result)) {
26             throw new \UnexpectedValueException($configKey . ' must be a list of settings to apply.');
27         }
28         $moreGeneralGroupname = $this->moreGeneralGroupName($group);
29         if ($moreGeneralGroupname) {
30             $result += $this->getWithMerge($key, $moreGeneralGroupname, $prefix, $postfix);
31         }
32         return $result;
33     }
34 }