Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

Pass an instance of \Handlebars\Arguments to a helper #91

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Handlebars/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ interface Helper
/**
* Execute the helper
*
* @param \Handlebars\Template $template The template instance
* @param \Handlebars\Context $context The current context
* @param array $args The arguments passed the the helper
* @param string $source The source
* @param \Handlebars\Template $template The template instance
* @param \Handlebars\Context $context The current context
* @param \Handlebars\Arguments $args The arguments passed the the helper
* @param string $source The source
*
* @return mixed
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Handlebars/Helper/BindAttrHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ class BindAttrHelper implements Helper
/**
* Execute the helper
*
* @param \Handlebars\Template $template The template instance
* @param \Handlebars\Context $context The current context
* @param array $args The arguments passed the the helper
* @param string $source The source
* @param \Handlebars\Template $template The template instance
* @param \Handlebars\Context $context The current context
* @param \Handlebars\Arguments $args The arguments passed the the helper
* @param string $source The source
*
* @return mixed
*/
Expand Down
11 changes: 6 additions & 5 deletions src/Handlebars/Helper/EachHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@ class EachHelper implements Helper
/**
* Execute the helper
*
* @param \Handlebars\Template $template The template instance
* @param \Handlebars\Context $context The current context
* @param array $args The arguments passed the the helper
* @param string $source The source
* @param \Handlebars\Template $template The template instance
* @param \Handlebars\Context $context The current context
* @param \Handlebars\Arguments $args The arguments passed the the helper
* @param string $source The source
*
* @return mixed
*/
public function execute(Template $template, Context $context, $args, $source)
{
$tmp = $context->get($args);
$positionalArgs = $args->getPositionalArguments();
$tmp = $context->get($positionalArgs[0]);
$buffer = '';

if (!$tmp) {
Expand Down
15 changes: 6 additions & 9 deletions src/Handlebars/Helper/IfHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,17 @@ class IfHelper implements Helper
/**
* Execute the helper
*
* @param \Handlebars\Template $template The template instance
* @param \Handlebars\Context $context The current context
* @param array $args The arguments passed the the helper
* @param string $source The source
* @param \Handlebars\Template $template The template instance
* @param \Handlebars\Context $context The current context
* @param \Handlebars\Arguments $args The arguments passed the the helper
* @param string $source The source
*
* @return mixed
*/
public function execute(Template $template, Context $context, $args, $source)
{
if (is_numeric($args)) {
$tmp = $args;
} else {
$tmp = $context->get($args);
}
$postionalArgs = $args->getPositionalArguments();
$tmp = $context->get($postionalArgs[0]);

$context->push($context->last());
if ($tmp) {
Expand Down
11 changes: 6 additions & 5 deletions src/Handlebars/Helper/UnlessHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@ class UnlessHelper implements Helper
/**
* Execute the helper
*
* @param \Handlebars\Template $template The template instance
* @param \Handlebars\Context $context The current context
* @param array $args The arguments passed the the helper
* @param string $source The source
* @param \Handlebars\Template $template The template instance
* @param \Handlebars\Context $context The current context
* @param \Handlebars\Arguments $args The arguments passed the the helper
* @param string $source The source
*
* @return mixed
*/
public function execute(Template $template, Context $context, $args, $source)
{
$tmp = $context->get($args);
$positionalArgs = $args->getPositionalArguments();
$tmp = $context->get($positionalArgs[0]);

$context->push($context->last());

Expand Down
11 changes: 6 additions & 5 deletions src/Handlebars/Helper/WithHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@ class WithHelper implements Helper
/**
* Execute the helper
*
* @param \Handlebars\Template $template The template instance
* @param \Handlebars\Context $context The current context
* @param array $args The arguments passed the the helper
* @param string $source The source
* @param \Handlebars\Template $template The template instance
* @param \Handlebars\Context $context The current context
* @param \Handlebars\Arguments $args The arguments passed the the helper
* @param string $source The source
*
* @return mixed
*/
public function execute(Template $template, Context $context, $args, $source)
{
$context->with($args);
$positionalArgs = $args->getPositionalArguments();
$context->with($positionalArgs[0]);
$buffer = $template->render($context);
$context->pop();

Expand Down
5 changes: 3 additions & 2 deletions src/Handlebars/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,14 @@ public function call($name, Template $template, Context $context, $args, $source
throw new \InvalidArgumentException('Unknown helper: ' . $name);
}

$parsedArgs = new Arguments($args);
if ($this->helpers[$name] instanceof Helper) {
return $this->helpers[$name]->execute(
$template, $context, $args, $source
$template, $context, $parsedArgs, $source
);
}

return call_user_func($this->helpers[$name], $template, $context, $args, $source);
return call_user_func($this->helpers[$name], $template, $context, $parsedArgs, $source);
}

/**
Expand Down