wrote this file. * As long as you retain this notice you can do whatever you want with * this stuff. If we meet some day, and you think this stuff is worth it, * you can buy me a beer in return. * * @author Sven Strittmatter * @copyright Copyright (c) 2010, Sven Strittmatter. * @version 0.2.0 * @license http://www.weltraumschaf.de/the-beer-ware-license.txt */ /** * Simple abstraction of an imutable configuration array. * * You can simply pass an array to the constructor. * * Example: * * 'bar', 'baz' = true); * $conf = new Api_Kwick_Config($arr); * * if ($conf->has('foo')) { * echo $conf->get('foo'); * } * * // ... * * * You can also load the config from a file like: * * 'bar', 'baz' = true); * * * Load the file: * * has('foo')) { * echo $conf->get('foo'); * } * * // ... * */ class Api_Kwick_Config { /** * Assoc array holds the configuration values. * * @var array */ private $config; /** * Initializes the configuration with given array. * * The passed array should be assoc. You access the values bey theres key. * * @param array $config The configuration array. */ public function __construct(array $config) { $this->config = $config; } /** * Returns whether a configuration key exists. * * @param string $name Name of the configuration key. * * @return bool */ public function has($name) { return array_key_exists((string) $name, $this->config); } /** * Returns a configuration by its key name. * * If the key does not exists the parameter passed by $default will * be returned. * * @param string $name Name of the configuration key. * @param mixed $default Fallback value. Default is null. * * @return mixed */ public function get($name, $default = null) { if ($this->has($name)) { return $this->config[(string) $name]; } return $default; } }