mirror of
				https://github.com/Mibew/handlebars.php.git
				synced 2025-11-04 04:05:07 +03:00 
			
		
		
		
	Merge pull request #92 from Mibew/use_args_class
Pass an instance of \Handlebars\Arguments to a helper -- it has some sort of BC break. need to be verified before rebasing this into master
This commit is contained in:
		
						commit
						a1b82c528b
					
				@ -33,7 +33,7 @@ interface Helper
 | 
				
			|||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param \Handlebars\Template  $template The template instance
 | 
					     * @param \Handlebars\Template  $template The template instance
 | 
				
			||||||
     * @param \Handlebars\Context   $context  The current context
 | 
					     * @param \Handlebars\Context   $context  The current context
 | 
				
			||||||
     * @param array                $args     The arguments passed the the helper
 | 
					     * @param \Handlebars\Arguments $args     The arguments passed the the helper
 | 
				
			||||||
     * @param string                $source   The source
 | 
					     * @param string                $source   The source
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return mixed
 | 
					     * @return mixed
 | 
				
			||||||
 | 
				
			|||||||
@ -43,7 +43,7 @@ class BindAttrHelper implements Helper
 | 
				
			|||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param \Handlebars\Template  $template The template instance
 | 
					     * @param \Handlebars\Template  $template The template instance
 | 
				
			||||||
     * @param \Handlebars\Context   $context  The current context
 | 
					     * @param \Handlebars\Context   $context  The current context
 | 
				
			||||||
     * @param array                $args     The arguments passed the the helper
 | 
					     * @param \Handlebars\Arguments $args     The arguments passed the the helper
 | 
				
			||||||
     * @param string                $source   The source
 | 
					     * @param string                $source   The source
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return mixed
 | 
					     * @return mixed
 | 
				
			||||||
 | 
				
			|||||||
@ -45,14 +45,15 @@ class EachHelper implements Helper
 | 
				
			|||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param \Handlebars\Template  $template The template instance
 | 
					     * @param \Handlebars\Template  $template The template instance
 | 
				
			||||||
     * @param \Handlebars\Context   $context  The current context
 | 
					     * @param \Handlebars\Context   $context  The current context
 | 
				
			||||||
     * @param array                $args     The arguments passed the the helper
 | 
					     * @param \Handlebars\Arguments $args     The arguments passed the the helper
 | 
				
			||||||
     * @param string                $source   The source
 | 
					     * @param string                $source   The source
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return mixed
 | 
					     * @return mixed
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function execute(Template $template, Context $context, $args, $source)
 | 
					    public function execute(Template $template, Context $context, $args, $source)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $tmp = $context->get($args);
 | 
					        $positionalArgs = $args->getPositionalArguments();
 | 
				
			||||||
 | 
					        $tmp = $context->get($positionalArgs[0]);
 | 
				
			||||||
        $buffer = '';
 | 
					        $buffer = '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!$tmp) {
 | 
					        if (!$tmp) {
 | 
				
			||||||
 | 
				
			|||||||
@ -43,18 +43,15 @@ class IfHelper implements Helper
 | 
				
			|||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param \Handlebars\Template  $template The template instance
 | 
					     * @param \Handlebars\Template  $template The template instance
 | 
				
			||||||
     * @param \Handlebars\Context   $context  The current context
 | 
					     * @param \Handlebars\Context   $context  The current context
 | 
				
			||||||
     * @param array                $args     The arguments passed the the helper
 | 
					     * @param \Handlebars\Arguments $args     The arguments passed the the helper
 | 
				
			||||||
     * @param string                $source   The source
 | 
					     * @param string                $source   The source
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return mixed
 | 
					     * @return mixed
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function execute(Template $template, Context $context, $args, $source)
 | 
					    public function execute(Template $template, Context $context, $args, $source)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (is_numeric($args)) {
 | 
					        $postionalArgs = $args->getPositionalArguments();
 | 
				
			||||||
            $tmp = $args;
 | 
					        $tmp = $context->get($postionalArgs[0]);
 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            $tmp = $context->get($args);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $context->push($context->last());
 | 
					        $context->push($context->last());
 | 
				
			||||||
        if ($tmp) {
 | 
					        if ($tmp) {
 | 
				
			||||||
 | 
				
			|||||||
@ -43,14 +43,15 @@ class UnlessHelper implements Helper
 | 
				
			|||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param \Handlebars\Template  $template The template instance
 | 
					     * @param \Handlebars\Template  $template The template instance
 | 
				
			||||||
     * @param \Handlebars\Context   $context  The current context
 | 
					     * @param \Handlebars\Context   $context  The current context
 | 
				
			||||||
     * @param array                $args     The arguments passed the the helper
 | 
					     * @param \Handlebars\Arguments $args     The arguments passed the the helper
 | 
				
			||||||
     * @param string                $source   The source
 | 
					     * @param string                $source   The source
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return mixed
 | 
					     * @return mixed
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function execute(Template $template, Context $context, $args, $source)
 | 
					    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());
 | 
					        $context->push($context->last());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -43,14 +43,15 @@ class WithHelper implements Helper
 | 
				
			|||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param \Handlebars\Template  $template The template instance
 | 
					     * @param \Handlebars\Template  $template The template instance
 | 
				
			||||||
     * @param \Handlebars\Context   $context  The current context
 | 
					     * @param \Handlebars\Context   $context  The current context
 | 
				
			||||||
     * @param array                $args     The arguments passed the the helper
 | 
					     * @param \Handlebars\Arguments $args     The arguments passed the the helper
 | 
				
			||||||
     * @param string                $source   The source
 | 
					     * @param string                $source   The source
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return mixed
 | 
					     * @return mixed
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function execute(Template $template, Context $context, $args, $source)
 | 
					    public function execute(Template $template, Context $context, $args, $source)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $context->with($args);
 | 
					        $positionalArgs = $args->getPositionalArguments();
 | 
				
			||||||
 | 
					        $context->with($positionalArgs[0]);
 | 
				
			||||||
        $buffer = $template->render($context);
 | 
					        $buffer = $template->render($context);
 | 
				
			||||||
        $context->pop();
 | 
					        $context->pop();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -124,13 +124,14 @@ class Helpers
 | 
				
			|||||||
            throw new \InvalidArgumentException('Unknown helper: ' . $name);
 | 
					            throw new \InvalidArgumentException('Unknown helper: ' . $name);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $parsedArgs = new Arguments($args);
 | 
				
			||||||
        if ($this->helpers[$name] instanceof Helper) {
 | 
					        if ($this->helpers[$name] instanceof Helper) {
 | 
				
			||||||
            return $this->helpers[$name]->execute(
 | 
					            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);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user