rendered paste body<?php
/**
*
* @author Veikko Makinen <mail@veikkomakinen.com
* @copyright (c) Authors
*
* @version $Id$
*/
class ConfigDirectivesConfigHandler extends AgaviConfigHandler
{
/**
* @see AgaviIniConfigHandler::execute()
*
*/
public function execute($config, $context = null)
{
$configurations = $this->orderConfigurations(AgaviConfigCache::parseConfig($config, false, $this->getValidationFile())->configurations, AgaviConfig::get('core.environment'), $context);
$code = '';
foreach($configurations as $cfg) {
$code .= $this->convert($cfg);
}
// compile data
$retval = "<?php\n" .
"// auto-generated by ".__CLASS__."\n" .
"// date: %s\n%s\n?>";
$retval = sprintf($retval, date('m/d/Y H:i:s'), $code);
return $retval;
}
/**
*
* @param AgaviConfigValueHolder The config value to convert.
*
* @author Veikko Makinen <mail@veikkomakinen.com>
*/
protected function convert(AgaviConfigValueHolder $item)
{
$prefix = '';
$data = '';
foreach($item->getChildren() as $directives) {
$prefix = $directives->getAttribute('prefix', '');
foreach($directives->getChildren() as $directive) {
$name = ($prefix ? $prefix.'.' : '') . $directive->getAttribute('name');
$value = var_export($this->literalize($this->replaceConstants($directive->getValue())), true);
$data .= "AgaviConfig::set('$name', $value); \n";
}
}
return $data;
}
}
?>