|
|
<?php |
|
|
|
|
|
namespace Kanboard\Helper; |
|
|
|
|
|
use Closure; |
|
|
use Kanboard\Core\Base; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HookHelper extends Base |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function asset($type, $hook) |
|
|
{ |
|
|
$buffer = ''; |
|
|
|
|
|
foreach ($this->hook->getListeners($hook) as $params) { |
|
|
$buffer .= $this->helper->asset->$type($params['template']); |
|
|
} |
|
|
|
|
|
return $buffer; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function render($hook, array $variables = array()) |
|
|
{ |
|
|
$buffer = ''; |
|
|
|
|
|
foreach ($this->hook->getListeners($hook) as $params) { |
|
|
$currentVariables = $variables; |
|
|
if (! empty($params['variables'])) { |
|
|
$currentVariables = array_merge($variables, $params['variables']); |
|
|
} elseif (! empty($params['callable'])) { |
|
|
$result = call_user_func_array($params['callable'], array_values($variables)); |
|
|
|
|
|
if (is_array($result)) { |
|
|
$currentVariables = array_merge($variables, $result); |
|
|
} |
|
|
} |
|
|
|
|
|
$buffer .= $this->template->render($params['template'], $currentVariables); |
|
|
} |
|
|
|
|
|
return $buffer; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function attach($hook, $template, array $variables = array()) |
|
|
{ |
|
|
$this->hook->on($hook, array( |
|
|
'template' => $template, |
|
|
'variables' => $variables, |
|
|
)); |
|
|
|
|
|
return $this; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function attachCallable($hook, $template, Closure $callable) |
|
|
{ |
|
|
$this->hook->on($hook, array( |
|
|
'template' => $template, |
|
|
'callable' => $callable, |
|
|
)); |
|
|
|
|
|
return $this; |
|
|
} |
|
|
} |
|
|
|