/** * Returns whether a configuration key is set. * * @param string $key The configuration key to search. * @param bool $fallback Whether to check the base configuration if the * key is not found. * * @return bool Returns `true` if the configuration key is set. * * @throws NoSuchConfigKeyException If the configuration key is invalid. */ public function contains($key, $fallback = true) { if (!isset(self::$compositeKeys[$key]) && !isset(self::$keys[$key])) { throw NoSuchConfigKeyException::forKey($key); } if (array_key_exists($key, $this->values)) { return true; } if (isset(self::$compositeKeys[$key]) && $this->containsKeyPrefix($key . '.')) { return true; } if ($fallback && $this->baseConfig) { return $this->baseConfig->contains($key); } return false; }
public function testContainsCompositeKeyWithoutFallback() { $baseConfig = new Config(); $config = new Config($baseConfig); $this->assertFalse($config->contains(Config::DISCOVERY, false)); $this->assertFalse($config->contains(Config::DISCOVERY_STORE, false)); $this->assertFalse($config->contains(Config::DISCOVERY_STORE_TYPE, false)); $baseConfig->set(Config::DISCOVERY, array('store' => array('type' => 'my-store-type'))); $this->assertFalse($config->contains(Config::DISCOVERY, false)); $this->assertFalse($config->contains(Config::DISCOVERY_STORE, false)); $this->assertFalse($config->contains(Config::DISCOVERY_STORE_TYPE, false)); }