*/ WBClass::load('WBConfig'); /** * patTemplate-function inject configuration value * * @version 0.2.0 * @package Wombat * @subpackage patTemplate */ class patTemplate_Function_Config extends patTemplate_Function { /** * Name of the function * @access protected * @var string */ public $_name = 'config'; /** * tell that this function must not be executed during runtime * @var string */ public $_type = PATTEMPLATE_FUNCTION_COMPILE; /** * Configuration Object * @var WBConfig */ private $config; /** * Constructor * */ public function __construct() { $this->config = WBClass::create('WBConfig'); } /** * Call the function * * @param array $params parameters of the function (= attributes of the tag) * @param string $content inside tag * @return string content to insert into the template */ public function call($params, $content) { if (empty($params['config'])) { $params['config'] = 'info'; } if (empty($params['default'])) { $params['default'] = ''; } $this->config->load($params['config']); $value = $this->config->get($content, $params['default']); if (empty($value)) { return ''; } if (is_scalar($value)) { return $value; } if (empty($params['format'])) { $params['format'] = '%s'; } if (empty($params['glue'])) { $params['glue'] = "
\n"; } $out = array(); foreach ($value as $k => $v) { $out[] = sprintf($params['format'], $v); } return implode($params['glue'], $out); } }