mirror of
				https://github.com/Mibew/handlebars.php.git
				synced 2025-11-04 12:05:09 +03:00 
			
		
		
		
	
		
			
				
	
	
		
			81 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			81 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
/**
 | 
						|
 * This file is part of Handlebars-php
 | 
						|
 *
 | 
						|
 * PHP version 5.3
 | 
						|
 *
 | 
						|
 * @category  Xamin
 | 
						|
 * @package   Handlebars
 | 
						|
 * @author    fzerorubigd <fzerorubigd@gmail.com>
 | 
						|
 * @author    Behrooz Shabani <everplays@gmail.com>
 | 
						|
 * @author    Dmitriy Simushev <simushevds@gmail.com>
 | 
						|
 * @author    Jeff Turcotte <jeff.turcotte@gmail.com>
 | 
						|
 * @copyright 2014 Authors
 | 
						|
 * @license   MIT <http://opensource.org/licenses/MIT>
 | 
						|
 * @version   GIT: $Id$
 | 
						|
 * @link      http://xamin.ir
 | 
						|
 */
 | 
						|
 | 
						|
namespace Handlebars\Helper;
 | 
						|
 | 
						|
use Handlebars\Context;
 | 
						|
use Handlebars\Helper;
 | 
						|
use Handlebars\Template;
 | 
						|
 | 
						|
/**
 | 
						|
 * The Unless Helper
 | 
						|
 *
 | 
						|
 * @category  Xamin
 | 
						|
 * @package   Handlebars
 | 
						|
 * @author    fzerorubigd <fzerorubigd@gmail.com>
 | 
						|
 * @author    Behrooz Shabani <everplays@gmail.com>
 | 
						|
 * @author    Dmitriy Simushev <simushevds@gmail.com>
 | 
						|
 * @author    Jeff Turcotte <jeff.turcotte@gmail.com>
 | 
						|
 * @copyright 2014 Authors
 | 
						|
 * @license   MIT <http://opensource.org/licenses/MIT>
 | 
						|
 * @version   Release: @package_version@
 | 
						|
 * @link      http://xamin.ir
 | 
						|
 */
 | 
						|
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
 | 
						|
     *
 | 
						|
     * @return mixed
 | 
						|
     */
 | 
						|
    public function execute(Template $template, Context $context, $args, $source)
 | 
						|
    {
 | 
						|
    	if (is_numeric($args)) {
 | 
						|
            $tmp = $args;
 | 
						|
        } elseif(preg_match('/^\'.*\'$/', trim($args))) {
 | 
						|
        	$tmp = preg_replace('/^\'(.*)\'$/', '$1', trim($args));
 | 
						|
        } elseif(preg_match('/^".*"$/', trim($args))) {
 | 
						|
        	$tmp = preg_replace('/^"(.*)"$/', '$1', trim($args));
 | 
						|
		} else {
 | 
						|
            $tmp = $context->get($args);
 | 
						|
        }
 | 
						|
 | 
						|
        $context->push($context->last());
 | 
						|
 | 
						|
        if (!$tmp) {
 | 
						|
            $template->setStopToken('else');
 | 
						|
            $buffer = $template->render($context);
 | 
						|
            $template->setStopToken(false);
 | 
						|
        } else {
 | 
						|
            $template->setStopToken('else');
 | 
						|
            $template->discard();
 | 
						|
            $template->setStopToken(false);
 | 
						|
            $buffer = $template->render($context);
 | 
						|
        }
 | 
						|
        
 | 
						|
        $context->pop();
 | 
						|
 | 
						|
        return $buffer;
 | 
						|
    }
 | 
						|
}
 |