/** * Returns the raw value of a configuration key. * * Unlike {@link get()}, this method does not resolve placeholders: * * ```php * $config = new Config(); * $config->set(Config::PULI_DIR, '.puli'); * $config->set(Config::INSTALL_FILE, '{$puli-dir}/install-file.json'); * * echo $config->get(Config::PULI_DIR); * // => .puli/install-file.json * * echo $config->getRaw(Config::PULI_DIR); * // => {$puli-dir}/install-file.json * ``` * * @param string $key The configuration key. * @param mixed $default The value to return if the key was not set. * @param bool $fallback Whether to return the value of the base * configuration if the key was not set. * * @return mixed The value of the configuration key. * * @throws NoSuchConfigKeyException If the configuration key is invalid. */ public function getRaw($key, $default = null, $fallback = true) { if (isset(self::$compositeKeys[$key])) { return array_replace_recursive(is_array($default) ? $default : array(), $fallback && $this->baseConfig ? $this->baseConfig->getRaw($key) : array(), $this->filterByKeyPrefix($key . '.')); } if (!isset(self::$keys[$key])) { throw NoSuchConfigKeyException::forKey($key); } if (!array_key_exists($key, $this->values) && $fallback && $this->baseConfig) { return $this->baseConfig->getRaw($key, $default); } return isset($this->values[$key]) ? $this->values[$key] : $default; }
public function testGetRawCompositeKeyDoesNotReplacePlaceholders() { $config = new Config(); $config->set(Config::PULI_DIR, 'puli-dir'); $config->set(Config::REPOSITORY_PATH, '{$puli-dir}/my-path'); $this->assertSame(array('path' => '{$puli-dir}/my-path'), $config->getRaw(Config::REPOSITORY)); }