Add the possibility to attach template hooks with a callback

This commit is contained in:
Frederic Guillot
2016-08-13 18:41:01 -04:00
parent 2ebe8b3272
commit 010199e8f8
4 changed files with 87 additions and 1 deletions

View File

@@ -46,6 +46,12 @@ class HookHelper extends Base
foreach ($this->hook->getListeners($hook) as $params) {
if (! empty($params['variables'])) {
$variables = array_merge($variables, $params['variables']);
} elseif (! empty($params['callable'])) {
$result = call_user_func_array($params['callable'], $variables);
if (is_array($result)) {
$variables = array_merge($variables, $result);
}
}
$buffer .= $this->template->render($params['template'], $variables);
@@ -72,4 +78,25 @@ class HookHelper extends Base
return $this;
}
/**
* Attach a template to a hook with a callable
*
* Arguments passed to the callback are the one passed to the hook
*
* @access public
* @param string $hook
* @param string $template
* @param callable $callable
* @return $this
*/
public function attachCallable($hook, $template, callable $callable)
{
$this->hook->on($hook, array(
'template' => $template,
'callable' => $callable,
));
return $this;
}
}