2 namespace Consolidation\Config\Util;
5 * Fetch a configuration value from a configuration group. If the
6 * desired configuration value is not found in the most specific
7 * group named, keep stepping up to the next parent group until a
10 * Given the following constructor inputs:
11 * - $prefix = "command."
12 * - $group = "foo.bar.baz"
13 * - $postfix = ".options."
14 * Then the `get` method will then consider, in order:
15 * - command.foo.bar.baz.options
16 * - command.foo.bar.options
17 * - command.foo.options
18 * If any of these contain an option for "$key", then return its value.
20 class ConfigFallback extends ConfigGroup
25 public function get($key)
27 return $this->getWithFallback($key, $this->group, $this->prefix, $this->postfix);
31 * Fetch an option value from a given key, or, if that specific key does
32 * not contain a value, then consult various fallback options until a
36 protected function getWithFallback($key, $group, $prefix = '', $postfix = '.')
38 $configKey = "{$prefix}{$group}${postfix}{$key}";
39 if ($this->config->has($configKey)) {
40 return $this->config->get($configKey);
42 if ($this->config->hasDefault($configKey)) {
43 return $this->config->getDefault($configKey);
45 $moreGeneralGroupname = $this->moreGeneralGroupName($group);
46 if ($moreGeneralGroupname) {
47 return $this->getWithFallback($key, $moreGeneralGroupname, $prefix, $postfix);