Optional initialization parameters:
*
* # prefix - The text prepended to all defined constant names.
*
* @package laiketui
* @subpackage config
*
* @author ketter (ketter@laiketui.com)
* @since 3.0.0
*/
class DefineConfigHandler extends IniConfigHandler
{
// +-----------------------------------------------------------------------+
// | METHODS |
// +-----------------------------------------------------------------------+
/**
* Execute this configuration handler.
*
* @param string An absolute filesystem path to a configuration file.
*
* @return string Data to be written to a cache file.
*
* @throws ConfigurationException If a requested configuration file
* does not exist or is not readable.
* @throws ParseException If a requested configuration file is
* improperly formatted.
*
* @author Sean Kerr (skerr@mojavi.org)
* @since 3.0.0
*/
public function & execute ($config)
{
// parse the ini
$ini = $this->parseIni($config);
// get our prefix
$prefix = $this->getParameter('prefix');
if ($prefix == null)
{
// no prefix has been specified
$prefix = '';
}
// init our data array
$data = array();
// let's do our fancy work
foreach ($ini as $category => &$keys)
{
// categories starting without a period will be prepended to the key
if ($category{0} != '.')
{
$category = $prefix . $category . '_';
} else
{
$category = $prefix;
}
// loop through all key/value pairs
foreach ($keys as $key => &$value)
{
// prefix the key
$key = $category . $key;
// replace constant values
$value = $this->replaceConstants($value);
// literalize our value
$value = $this->literalize($value);
// append new data
$tmp = "define('%s', %s);";
$data[] = sprintf($tmp, $key, $value);
}
}
// compile data
$retval = "";
$retval = sprintf($retval, date('m/d/Y H:i:s'), implode("\n", $data));
return $retval;
}
}
?>