function _compile_compiler_tag($tagCommand, $tagArgs, &$output) { //We first try to use Smarty's own functionality to parse the tag $found = parent::_compile_compiler_tag($tagCommand, $tagArgs, $output); if ($found === false) { try { //Check if helper exists and create output $this->zendView->getHelper($tagCommand); $helperArgs = array(); if ($tagArgs !== null) { //Start parsing our custom syntax $params = explode(' ', $tagArgs); foreach ($params as $p) { //Split each key=value pair to vars list($key, $value) = explode('=', $p, 2); $section = ''; //If there's a dot in the key, it means we //need to use associative arrays if (strpos('.', $key) != -1) { list($key, $section) = explode('.', $key); } //Use Smarty's own functions to parse the value //so that if there's a variable, it gets changed to //properly point at a template variable etc. $value = $this->_parse_var_props($value); //Put the value into the arg array if ($section == '') { if (array_key_exists($key, $helperArgs)) { if (is_array($helperArgs[$key])) { $helperArgs[$key][] = $value; } else { $helperArgs[$key] = array($helperArgs[$key], $value); } } else { $helperArgs[$key] = $value; } } else { if (!is_array($helperArgs[$key])) { $helperArgs[$key] = array(); } $helperArgs[$key][$section] = $value; } } } //Save the code to put to the template in the output $output = "<?php echo \$this->callViewHelper('{$tagCommand}',array(" . $this->_createParameterCode($helperArgs) . ")); ?>"; $found = true; } catch (Exception $e) { //Exception means the helper was not found $found = false; fwrite(fopen('php://stderr', 'a'), $e->getMessage()); } } return $found; }
/** * @param string $name * @param mixed $args * @return mixed The helper return */ public function callViewHelper($name, $args) { $helper = $this->zendView->getHelper($name); return call_user_func_array(array($helper, $name), $args); }