function actionDefault() { // Set some variables YDConfig::set('MyConfigVar1', 'value cfg1'); YDConfig::set('MyConfigVar2', 'value cfg2'); YDConfig::set('MyConfigVar3', 'value cfg3'); // Get the values YDDebugUtil::dump(YDConfig::get('MyConfigVar1'), 'get - MyConfigVar1'); YDDebugUtil::dump(YDConfig::get('MyConfigVar2'), 'get - MyConfigVar2'); YDDebugUtil::dump(YDConfig::get('MyConfigVar3'), 'get - MyConfigVar3'); // Check if the variables exist or not YDDebugUtil::dump(YDConfig::exists('MyConfigVar1'), 'exists - MyConfigVar1'); YDDebugUtil::dump(YDConfig::exists('MyConfigVar2'), 'exists - MyConfigVar2'); YDDebugUtil::dump(YDConfig::exists('MyConfigVar3'), 'exists - MyConfigVar3'); // Check an unexisting variable YDDebugUtil::dump(YDConfig::exists('xx'), 'exists - xx'); // Set some variables, not overriding existing values YDConfig::set('MyConfigVar1', 'value cfg1 changed', false); YDConfig::set('MyConfigVar2', 'value cfg2 changed', false); YDConfig::set('MyConfigVar3', 'value cfg3 changed', false); // Get the values (should be unchanged) YDDebugUtil::dump(YDConfig::get('MyConfigVar1'), 'get - MyConfigVar1 - changed1'); YDDebugUtil::dump(YDConfig::get('MyConfigVar2'), 'get - MyConfigVar2 - changed1'); YDDebugUtil::dump(YDConfig::get('MyConfigVar3'), 'get - MyConfigVar3 - changed1'); // Set some variables, overriding existing values YDConfig::set('MyConfigVar1', 'value cfg1 changed', true); YDConfig::set('MyConfigVar2', 'value cfg2 changed', true); YDConfig::set('MyConfigVar3', 'value cfg3 changed', true); // Get the values (should be changed) YDDebugUtil::dump(YDConfig::get('MyConfigVar1'), 'get - MyConfigVar1 - changed2'); YDDebugUtil::dump(YDConfig::get('MyConfigVar2'), 'get - MyConfigVar2 - changed2'); YDDebugUtil::dump(YDConfig::get('MyConfigVar3'), 'get - MyConfigVar3 - changed2'); // Dump the contents of YDConfig YDConfig::dump(); }
/** * This function returns a variable from the configuration. If the configuration variable doesn't exist, it * returns a fatal error. * * @param $name The name of the configuration variable to retrieve. * * @returns The value of the configuration variable. */ function get($name) { // Raise an error if an invalid configuration setting if (!YDConfig::exists($name)) { trigger_error('Configuration variable "' . $name . '" is not defined.', YD_ERROR); } // Return the value return $GLOBALS[YD_CONFIG_VAR][$name]; }
/** * This function returns a variable from the configuration. If the configuration variable doesn't exist, it * returns a fatal error. * * @param $name The name of the configuration variable to retrieve. * @param $default (optional) If not null, this value will be returned if the configuration setting doesn't * exist in the configuration. * * @returns The value of the configuration variable. */ function get($name, $default = null) { return YDConfig::exists($name) ? $GLOBALS[YD_CONFIG_VAR][$name] : $default; }
/** * This function returns a variable from the configuration. If the configuration variable doesn't exist, it * returns a fatal error. * * @param $name The name of the configuration variable to retrieve. * @param $default (optional) If not null, this value will be returned if the configuration setting doesn't * exist in the configuration. * * @returns The value of the configuration variable. */ function get($name, $default = null) { // Check if the key exists if (!YDConfig::exists($name)) { // Return the default return $default; } // Return the value return $GLOBALS[YD_CONFIG_VAR][$name]; }