use PHP CodeSniffer's coding standards

This commit is contained in:
behrooz shabani (everplays) 2013-11-05 14:12:44 +03:30
parent 4999f204f9
commit e513648544
15 changed files with 409 additions and 279 deletions

View File

@ -10,12 +10,15 @@
* @category Xamin * @category Xamin
* @package Handlebars * @package Handlebars
* @author fzerorubigd <fzerorubigd@gmail.com> * @author fzerorubigd <fzerorubigd@gmail.com>
* @author Behrooz Shabani <everplays@gmail.com>
* @copyright 2012 (c) ParsPooyesh Co * @copyright 2012 (c) ParsPooyesh Co
* @copyright 2013 (c) Behrooz Shabani
* @license MIT <http://opensource.org/licenses/MIT> * @license MIT <http://opensource.org/licenses/MIT>
* @version GIT: $Id$ * @version GIT: $Id$
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars;
/** /**
* Autloader for handlebars.php * Autloader for handlebars.php
@ -28,7 +31,6 @@
* @version Release: @package_version@ * @version Release: @package_version@
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars;
class Autoloader class Autoloader
{ {
@ -38,12 +40,13 @@ class Autoloader
/** /**
* Autoloader constructor. * Autoloader constructor.
* *
* @param string $baseDir Handlebars library base directory (default: dirname(__FILE__).'/..') * @param string $baseDir Handlebars library base directory default is
* __DIR__.'/..'
*/ */
public function __construct($baseDir = null) public function __construct($baseDir = null)
{ {
if ($baseDir === null) { if ($baseDir === null) {
$this->_baseDir = dirname(__FILE__).'/..'; $this->_baseDir = __DIR__.'/..';
} else { } else {
$this->_baseDir = rtrim($baseDir, '/'); $this->_baseDir = rtrim($baseDir, '/');
} }
@ -52,7 +55,8 @@ class Autoloader
/** /**
* Register a new instance as an SPL autoloader. * Register a new instance as an SPL autoloader.
* *
* @param string $baseDir Handlebars library base directory (default: dirname(__FILE__).'/..') * @param string $baseDir Handlebars library base directory, default is
* __DIR__.'/..'
* *
* @return Handlebars_Autoloader Registered Autoloader instance * @return Handlebars_Autoloader Registered Autoloader instance
*/ */
@ -86,4 +90,5 @@ class Autoloader
include $file; include $file;
} }
} }
} }

View File

@ -8,12 +8,15 @@
* @category Xamin * @category Xamin
* @package Handlebars * @package Handlebars
* @author fzerorubigd <fzerorubigd@gmail.com> * @author fzerorubigd <fzerorubigd@gmail.com>
* @author Behrooz Shabani <everplays@gmail.com>
* @copyright 2012 (c) ParsPooyesh Co * @copyright 2012 (c) ParsPooyesh Co
* @copyright 2013 (c) Behrooz Shabani
* @license MIT <http://opensource.org/licenses/MIT> * @license MIT <http://opensource.org/licenses/MIT>
* @version GIT: $Id$ * @version GIT: $Id$
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars;
/** /**
* Cache interface * Cache interface
@ -29,10 +32,9 @@
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars;
interface Cache interface Cache
{ {
/** /**
* Get cache for $name if exist. * Get cache for $name if exist.
* *
@ -60,4 +62,5 @@ interface Cache
* @return void * @return void
*/ */
public function remove($name); public function remove($name);
} }

View File

@ -8,12 +8,16 @@
* @category Xamin * @category Xamin
* @package Handlebars * @package Handlebars
* @author Joey Baker <joey@byjoeybaker.com> * @author Joey Baker <joey@byjoeybaker.com>
* @author Behrooz Shabani <everplays@gmail.com>
* @copyright 2013 (c) Meraki, LLP * @copyright 2013 (c) Meraki, LLP
* @copyright 2013 (c) Behrooz Shabani
* @license MIT <http://opensource.org/licenses/MIT> * @license MIT <http://opensource.org/licenses/MIT>
* @version GIT: $Id$ * @version GIT: $Id$
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars\Cache;
use Handlebars\Cache;
/** /**
* A dummy array cache * A dummy array cache
@ -26,11 +30,9 @@
* @version Release: @package_version@ * @version Release: @package_version@
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars\Cache;
class APC implements Cache class APC implements Cache
{ {
private $_cache = array();
/** /**
* Get cache for $name if exist. * Get cache for $name if exist.
@ -41,10 +43,10 @@ class APC implements Cache
*/ */
public function get($name) public function get($name)
{ {
if (apc_exists($name)){ if (apc_exists($name)) {
return apc_fetch($name); return apc_fetch($name);
} }
return false; return false;
} }
/** /**
@ -71,4 +73,5 @@ class APC implements Cache
{ {
apc_delete($name); apc_delete($name);
} }
} }

View File

@ -8,12 +8,16 @@
* @category Xamin * @category Xamin
* @package Handlebars * @package Handlebars
* @author Alex Soncodi <alex@brokerloop.com> * @author Alex Soncodi <alex@brokerloop.com>
* @author Behrooz Shabani <everplays@gmail.com>
* @copyright 2013 (c) Brokerloop, Inc. * @copyright 2013 (c) Brokerloop, Inc.
* @copyright 2013 (c) Behrooz Shabani
* @license MIT <http://opensource.org/licenses/MIT> * @license MIT <http://opensource.org/licenses/MIT>
* @version GIT: $Id$ * @version GIT: $Id$
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars\Cache;
use Handlebars\Cache;
/** /**
* A flat-file filesystem cache. * A flat-file filesystem cache.
@ -27,8 +31,9 @@
* @link http://xamin.ir * @link http://xamin.ir
*/ */
class Handlebars_Cache_Disk implements Handlebars_Cache class Disk implements Cache
{ {
private $_path = ''; private $_path = '';
private $_prefix = ''; private $_prefix = '';
private $_suffix = ''; private $_suffix = '';
@ -36,7 +41,7 @@ class Handlebars_Cache_Disk implements Handlebars_Cache
/** /**
* Construct the disk cache. * Construct the disk cache.
* *
* @param string $path Filesystem path to the disk cache location * @param string $path Filesystem path to the disk cache location
* @param string $prefix optional file prefix, defaults to empty string * @param string $prefix optional file prefix, defaults to empty string
* @param string $suffix optional file extension, defaults to empty string * @param string $suffix optional file extension, defaults to empty string
*/ */
@ -44,8 +49,7 @@ class Handlebars_Cache_Disk implements Handlebars_Cache
{ {
if (empty($path)) { if (empty($path)) {
throw new InvalidArgumentException('Must specify disk cache path'); throw new InvalidArgumentException('Must specify disk cache path');
} } elseif (!is_dir($path)) {
else if (!is_dir($path)) {
@mkdir($path, 0777, true); @mkdir($path, 0777, true);
if (!is_dir($path)) { if (!is_dir($path)) {
@ -64,8 +68,10 @@ class Handlebars_Cache_Disk implements Handlebars_Cache
* and optional extension. * and optional extension.
* *
* @param string $name Name of the cache item * @param string $name Name of the cache item
*
* @return string full disk path of cached item
*/ */
private function getPath($name) private function _getPath($name)
{ {
return $this->_path . DIRECTORY_SEPARATOR . return $this->_path . DIRECTORY_SEPARATOR .
$this->_prefix . $name . $this->_suffix; $this->_prefix . $name . $this->_suffix;
@ -80,7 +86,7 @@ class Handlebars_Cache_Disk implements Handlebars_Cache
*/ */
public function get($name) public function get($name)
{ {
$path = $this->getPath($name); $path = $this->_getPath($name);
return (file_exists($path)) ? return (file_exists($path)) ?
unserialize(file_get_contents($path)) : false; unserialize(file_get_contents($path)) : false;
@ -96,7 +102,7 @@ class Handlebars_Cache_Disk implements Handlebars_Cache
*/ */
public function set($name, $value) public function set($name, $value)
{ {
$path = $this->getPath($name); $path = $this->_getPath($name);
file_put_contents($path, serialize($value)); file_put_contents($path, serialize($value));
} }
@ -110,8 +116,9 @@ class Handlebars_Cache_Disk implements Handlebars_Cache
*/ */
public function remove($name) public function remove($name)
{ {
$path = $this->getPath($name); $path = $this->_getPath($name);
unlink($path); unlink($path);
} }
} }

View File

@ -8,12 +8,16 @@
* @category Xamin * @category Xamin
* @package Handlebars * @package Handlebars
* @author fzerorubigd <fzerorubigd@gmail.com> * @author fzerorubigd <fzerorubigd@gmail.com>
* @author Behrooz Shabani <everplays@gmail.com>
* @copyright 2012 (c) ParsPooyesh Co * @copyright 2012 (c) ParsPooyesh Co
* @copyright 2013 (c) Behrooz Shabani
* @license MIT <http://opensource.org/licenses/MIT> * @license MIT <http://opensource.org/licenses/MIT>
* @version GIT: $Id$ * @version GIT: $Id$
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars\Cache;
use Handlebars\Cache;
/** /**
* A dummy array cache * A dummy array cache
@ -27,8 +31,6 @@
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars\Cache;
use Handlebars\Cache;
class Dummy implements Cache class Dummy implements Cache
{ {
private $_cache = array(); private $_cache = array();
@ -72,4 +74,5 @@ class Dummy implements Cache
{ {
unset($this->_cache[$name]); unset($this->_cache[$name]);
} }
} }

View File

@ -10,11 +10,14 @@
* @author fzerorubigd <fzerorubigd@gmail.com> * @author fzerorubigd <fzerorubigd@gmail.com>
* @author Behrooz Shabani <everplays@gmail.com> * @author Behrooz Shabani <everplays@gmail.com>
* @copyright 2012 (c) ParsPooyesh Co * @copyright 2012 (c) ParsPooyesh Co
* @copyright 2013 (c) Behrooz Shabani
* @license MIT <http://opensource.org/licenses/MIT> * @license MIT <http://opensource.org/licenses/MIT>
* @version GIT: $Id$ * @version GIT: $Id$
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars;
/** /**
* Handlebars context * Handlebars context
* Context for a template * Context for a template
@ -28,16 +31,15 @@
* @version Release: @package_version@ * @version Release: @package_version@
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars;
class Context class Context
{ {
/** /**
* @var array stack for context only top stack is available * @var array stack for context only top stack is available
*/ */
protected $stack = array(); protected $stack = array();
/** /**
* @var index stack for sections * @var index stack for sections
*/ */
@ -75,7 +77,9 @@ class Context
/** /**
* Push an Index onto the index stack * Push an Index onto the index stack
* *
* @param int $index Index of the current section item. * @param integer $index Index of the current section item.
*
* @return void
*/ */
public function pushIndex($index) public function pushIndex($index)
{ {
@ -86,6 +90,8 @@ class Context
* Push a Key onto the key stack * Push a Key onto the key stack
* *
* @param string $key Key of the current object property. * @param string $key Key of the current object property.
*
* @return void
*/ */
public function pushKey($key) public function pushKey($key)
{ {
@ -102,7 +108,6 @@ class Context
return array_pop($this->stack); return array_pop($this->stack);
} }
/** /**
* Pop the last index from the stack. * Pop the last index from the stack.
* *
@ -176,7 +181,7 @@ class Context
* @param boolean $strict strict search? if not found then throw exception * @param boolean $strict strict search? if not found then throw exception
* *
* @return mixed * @return mixed
* @throw InvalidArgumentException in strict mode and variable not found * @throws InvalidArgumentException in strict mode and variable not found
*/ */
public function get($variableName, $strict = false) public function get($variableName, $strict = false)
{ {
@ -189,7 +194,9 @@ class Context
} }
if (count($this->stack) < $level) { if (count($this->stack) < $level) {
if ($strict) { if ($strict) {
throw new \InvalidArgumentException('can not find variable in context'); throw new \InvalidArgumentException(
'can not find variable in context'
);
} }
return ''; return '';
} }
@ -201,7 +208,9 @@ class Context
$current = current($this->stack); $current = current($this->stack);
if (!$variableName) { if (!$variableName) {
if ($strict) { if ($strict) {
throw new \InvalidArgumentException('can not find variable in context'); throw new \InvalidArgumentException(
'can not find variable in context'
);
} }
return ''; return '';
} elseif ($variableName == '.' || $variableName == 'this') { } elseif ($variableName == '.' || $variableName == 'this') {
@ -226,7 +235,7 @@ class Context
* @param boolean $strict strict search? if not found then throw exception * @param boolean $strict strict search? if not found then throw exception
* *
* @return boolean true if exist * @return boolean true if exist
* @throw InvalidArgumentException in strict mode and variable not found * @throws InvalidArgumentException in strict mode and variable not found
*/ */
private function _findVariableInContext($variable, $inside, $strict = false) private function _findVariableInContext($variable, $inside, $strict = false)
{ {
@ -250,4 +259,5 @@ class Context
} }
return $value; return $value;
} }
} }

View File

@ -1,23 +1,27 @@
<?php <?php
/** /**
* This file is part of Handlebars-php * This file is part of Handlebars-php
* Base on mustache-php https://github.com/bobthecow/mustache.php * Based on mustache-php https://github.com/bobthecow/mustache.php
* *
* PHP version 5.3 * PHP version 5.3
* *
* @category Xamin * @category Xamin
* @package Handlebars * @package Handlebars
* @author fzerorubigd <fzerorubigd@gmail.com> * @author fzerorubigd <fzerorubigd@gmail.com>
* @author Behrooz Shabani <everplays@gmail.com>
* @copyright 2012 (c) ParsPooyesh Co * @copyright 2012 (c) ParsPooyesh Co
* @copyright 2013 (c) Behrooz Shabani
* @license MIT <http://opensource.org/licenses/MIT> * @license MIT <http://opensource.org/licenses/MIT>
* @version GIT: $Id$ * @version GIT: $Id$
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars;
use Handlebars\Loader\StringLoader;
use Handlebars\Cache\Dummy;
/** /**
* Handlebars parser (infact its a mustache parser) * Handlebars template engine, based on mustache.
* This class is responsible for turning raw template source into a set of Mustache tokens.
* *
* @category Xamin * @category Xamin
* @package Handlebars * @package Handlebars
@ -27,20 +31,25 @@
* @version Release: @package_version@ * @version Release: @package_version@
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars;
use Handlebars\Loader\StringLoader;
use Handlebars\Cache\Dummy;
class Handlebars class Handlebars
{ {
private static $instance = false; private static $_instance = false;
const VERSION = '1.0.0'; const VERSION = '1.0.0';
public static function factory ($options=array()) { /**
if (self::$instance === false) { * factory method
self::$instance = new Handlebars($options); *
* @param array $options see __construct's options parameter
*
* @return void
*/
public static function factory ($options=array())
{
if (self::$_instance === false) {
self::$_instance = new Handlebars($options);
} }
return self::$instance; return self::$_instance;
} }
/** /**
@ -52,6 +61,7 @@ class Handlebars
* @var Parser * @var Parser
*/ */
private $_parser; private $_parser;
/** /**
* @var Helpers * @var Helpers
*/ */
@ -71,20 +81,22 @@ class Handlebars
* @var Cache * @var Cache
*/ */
private $_cache; private $_cache;
/** /**
* @var callable escape function to use * @var callable escape function to use
*/ */
private $_escape = 'htmlspecialchars'; private $_escape = 'htmlspecialchars';
/** /**
* @var array parametes to pass to escape function, script prepend string to this array * @var array parametes to pass to escape function
*/ */
private $_escapeArgs = array ( private $_escapeArgs = array (
ENT_COMPAT, ENT_COMPAT,
'UTF-8' 'UTF-8'
); );
private $_aliases = array(); private $_aliases = array();
/** /**
* Handlebars engine constructor * Handlebars engine constructor
* $options array can contain : * $options array can contain :
@ -117,7 +129,9 @@ class Handlebars
if (isset($options['escape'])) { if (isset($options['escape'])) {
if (!is_callable($options['escape'])) { if (!is_callable($options['escape'])) {
throw new \InvalidArgumentException('Handlebars Constructor "escape" option must be callable'); throw new \InvalidArgumentException(
'Handlebars Constructor "escape" option must be callable'
);
} }
$this->_escape = $options['escape']; $this->_escape = $options['escape'];
@ -323,7 +337,9 @@ class Handlebars
public function setEscape($escape) public function setEscape($escape)
{ {
if (!is_callable($escape)) { if (!is_callable($escape)) {
throw new \InvalidArgumentException('Escape function must be a callable'); throw new \InvalidArgumentException(
'Escape function must be a callable'
);
} }
$this->_escape = $escape; $this->_escape = $escape;
} }
@ -369,7 +385,8 @@ class Handlebars
/** /**
* Get the current Handlebars Tokenizer instance. * Get the current Handlebars Tokenizer instance.
* *
* If no Tokenizer instance has been explicitly specified, this method will instantiate and return a new one. * If no Tokenizer instance has been explicitly specified, this method will
* instantiate and return a new one.
* *
* @return Tokenizer * @return Tokenizer
*/ */
@ -396,7 +413,8 @@ class Handlebars
/** /**
* Get the current Handlebars Parser instance. * Get the current Handlebars Parser instance.
* *
* If no Parser instance has been explicitly specified, this method will instantiate and return a new one. * If no Parser instance has been explicitly specified, this method will
* instantiate and return a new one.
* *
* @return Parser * @return Parser
*/ */
@ -497,4 +515,5 @@ class Handlebars
} }
return $tree; return $tree;
} }
} }

View File

@ -8,17 +8,23 @@
* @category Xamin * @category Xamin
* @package Handlebars * @package Handlebars
* @author fzerorubigd <fzerorubigd@gmail.com> * @author fzerorubigd <fzerorubigd@gmail.com>
* @author Behrooz Shabani <everplays@gmail.com>
* @copyright 2012 (c) ParsPooyesh Co * @copyright 2012 (c) ParsPooyesh Co
* @copyright 2013 (c) Behrooz Shabani
* @license MIT <http://opensource.org/licenses/MIT> * @license MIT <http://opensource.org/licenses/MIT>
* @version GIT: $Id$ * @version GIT: $Id$
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars;
/** /**
* Handlebars helpers * Handlebars helpers
* *
* a collection of helper function. normally a function like * a collection of helper function. normally a function like
* function ($sender, $name, $arguments) $arguments is unscaped arguments and is a string, not array * function ($sender, $name, $arguments) $arguments is unscaped arguments and
* is a string, not array
*
* TODO: Add support for an interface with an execute method * TODO: Add support for an interface with an execute method
* *
* @category Xamin * @category Xamin
@ -29,7 +35,6 @@
* @version Release: @package_version@ * @version Release: @package_version@
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars;
class Helpers class Helpers
{ {
@ -44,7 +49,8 @@ class Helpers
* @param array $helpers array of name=>$value helpers * @param array $helpers array of name=>$value helpers
* @param array $defaults add defaults helper (if, unless, each,with) * @param array $defaults add defaults helper (if, unless, each,with)
* *
* @throw InvalidArgumentException when $helpers is not an array (or traversable) or helper is not a caallable * @throws InvalidArgumentException when $helpers is not an array
* (or traversable) or helper is not a callable
*/ */
public function __construct($helpers = null, $defaults = true) public function __construct($helpers = null, $defaults = true)
{ {
@ -53,7 +59,9 @@ class Helpers
} }
if ($helpers != null) { if ($helpers != null) {
if (!is_array($helpers) && !$helpers instanceof Traversable) { if (!is_array($helpers) && !$helpers instanceof Traversable) {
throw new \InvalidArgumentException('HelperCollection constructor expects an array of helpers'); throw new \InvalidArgumentException(
'HelperCollection constructor expects an array of helpers'
);
} }
foreach ($helpers as $name => $helper) { foreach ($helpers as $name => $helper) {
$this->add($name, $helpers); $this->add($name, $helpers);
@ -61,124 +69,141 @@ class Helpers
} }
} }
/** /**
* Create handler for the 'if' helper. * Create handler for the 'if' helper.
* Needed for compatibility with PHP 5.2 since it doesn't support anonymous functions. *
* * Needed for compatibility with PHP 5.2 since it doesn't support anonymous
* @param $template * functions.
* @param $context *
* @param $args * @param Handlebars\Template $template template that is being rendered
* @param $source * @param Handlebars\Context $context context object
* * @param array $args passed arguments to helper
* @return mixed * @param string $source part of template that is wrapped
*/ * within helper
public static function _helper_if($template, $context, $args, $source) { *
$tmp = $context->get($args); * @return mixed
$buffer = ''; */
public static function helperIf($template, $context, $args, $source)
{
$tmp = $context->get($args);
$buffer = '';
if ($tmp) { if ($tmp) {
$template->setStopToken('else'); $template->setStopToken('else');
$buffer = $template->render($context); $buffer = $template->render($context);
$template->setStopToken(false); $template->setStopToken(false);
$template->discard($context); $template->discard($context);
} else { } else {
$template->setStopToken('else'); $template->setStopToken('else');
$template->discard($context); $template->discard($context);
$template->setStopToken(false); $template->setStopToken(false);
$buffer = $template->render($context); $buffer = $template->render($context);
} }
return $buffer; return $buffer;
} }
/** /**
* Create handler for the 'each' helper. * Create handler for the 'each' helper.
* Needed for compatibility with PHP 5.2 since it doesn't support anonymous functions. *
* * Needed for compatibility with PHP 5.2 since it doesn't support anonymous
* @param $template * functions.
* @param $context *
* @param $args * @param Handlebars\Template $template template that is being rendered
* @param $source * @param Handlebars\Context $context context object
* * @param array $args passed arguments to helper
* @return mixed * @param string $source part of template that is wrapped
*/ * within helper
public static function _helper_each($template, $context, $args, $source) { *
$tmp = $context->get($args); * @return mixed
$buffer = ''; */
if (is_array($tmp) || $tmp instanceof Traversable) { public static function helperEach($template, $context, $args, $source)
$islist = ( array_keys($tmp) == range(0, count($tmp) - 1) ); {
$tmp = $context->get($args);
$buffer = '';
if (is_array($tmp) || $tmp instanceof Traversable) {
$islist = ( array_keys($tmp) == range(0, count($tmp) - 1) );
foreach ($tmp as $key => $var) { foreach ($tmp as $key => $var) {
if( $islist ) { if ( $islist ) {
$context->pushIndex($key); $context->pushIndex($key);
} else { } else {
$context->pushKey($key); $context->pushKey($key);
} }
$context->push($var); $context->push($var);
$buffer .= $template->render($context); $buffer .= $template->render($context);
$context->pop(); $context->pop();
if( $islist ) { if ( $islist ) {
$context->popIndex(); $context->popIndex();
} else { } else {
$context->popKey(); $context->popKey();
} }
} }
} }
return $buffer; return $buffer;
} }
/** /**
* Create handler for the 'unless' helper. * Create handler for the 'unless' helper.
* Needed for compatibility with PHP 5.2 since it doesn't support anonymous functions. * Needed for compatibility with PHP 5.2 since it doesn't support anonymous
* * functions.
* @param $template *
* @param $context * @param Handlebars\Template $template template that is being rendered
* @param $args * @param Handlebars\Context $context context object
* @param $source * @param array $args passed arguments to helper
* * @param string $source part of template that is wrapped
* @return mixed * within helper
*/ *
public static function _helper_unless($template, $context, $args, $source) { * @return mixed
$tmp = $context->get($args); */
$buffer = ''; public static function helperUnless($template, $context, $args, $source)
if (!$tmp) { {
$buffer = $template->render($context); $tmp = $context->get($args);
} $buffer = '';
return $buffer; if (!$tmp) {
} $buffer = $template->render($context);
}
return $buffer;
}
/** /**
* Create handler for the 'with' helper. * Create handler for the 'with' helper.
* Needed for compatibility with PHP 5.2 since it doesn't support anonymous functions. * Needed for compatibility with PHP 5.2 since it doesn't support anonymous
* * functions.
* @param $template *
* @param $context * @param Handlebars\Template $template template that is being rendered
* @param $args * @param Handlebars\Context $context context object
* @param $source * @param array $args passed arguments to helper
* * @param string $source part of template that is wrapped
* @return mixed * within helper
*/ *
public static function _helper_with($template, $context, $args, $source) { * @return mixed
$tmp = $context->get($args); */
$context->push($tmp); public static function helperWith($template, $context, $args, $source)
$buffer = $template->render($context); {
$context->pop(); $tmp = $context->get($args);
return $buffer; $context->push($tmp);
} $buffer = $template->render($context);
$context->pop();
return $buffer;
}
/** /**
* Create handler for the 'bindAttr' helper. * Create handler for the 'bindAttr' helper.
* Needed for compatibility with PHP 5.2 since it doesn't support anonymous functions. * Needed for compatibility with PHP 5.2 since it doesn't support anonymous
* * functions.
* @param $template *
* @param $context * @param Handlebars\Template $template template that is being rendered
* @param $args * @param Handlebars\Context $context context object
* @param $source * @param array $args passed arguments to helper
* * @param string $source part of template that is wrapped
* @return mixed * within helper
*/ *
public static function _helper_bindAttr($template, $context, $args, $source) { * @return mixed
return $args; */
} public static function helperBindAttr($template, $context, $args, $source)
{
return $args;
}
/** /**
* Add default helpers (if unless each with bindAttr) * Add default helpers (if unless each with bindAttr)
@ -189,28 +214,28 @@ class Helpers
{ {
$this->add( $this->add(
'if', 'if',
array('Handlebars\Helpers', '_helper_if') array('Handlebars\Helpers', 'helperIf')
); );
$this->add( $this->add(
'each', 'each',
array('Handlebars\Helpers', '_helper_each') array('Handlebars\Helpers', 'helperEach')
); );
$this->add( $this->add(
'unless', 'unless',
array('Handlebars\Helpers', '_helper_unless') array('Handlebars\Helpers', 'helperUnless')
); );
$this->add( $this->add(
'with', 'with',
array('Handlebars\Helpers', '_helper_with') array('Handlebars\Helpers', 'helperWith')
); );
//Just for compatibility with ember //Just for compatibility with ember
$this->add( $this->add(
'bindAttr', 'bindAttr',
array('Handlebars\Helpers', '_helper_bindAttr') array('Handlebars\Helpers', 'helperBindAttr')
); );
} }
@ -221,7 +246,7 @@ class Helpers
* @param callable $helper a function as a helper * @param callable $helper a function as a helper
* *
* @return void * @return void
* @throw InvalidArgumentException if $helper is not a callable * @throws InvalidArgumentException if $helper is not a callable
*/ */
public function add($name ,$helper) public function add($name ,$helper)
{ {
@ -249,7 +274,7 @@ class Helpers
* @param string $name helper name * @param string $name helper name
* *
* @return callable helper function * @return callable helper function
* @throw InvalidArgumentException if $name is not available * @throws InvalidArgumentException if $name is not available
*/ */
public function __get($name) public function __get($name)
{ {
@ -279,7 +304,7 @@ class Helpers
* @param callable $helper a function as a helper * @param callable $helper a function as a helper
* *
* @return void * @return void
* @throw InvalidArgumentException if $helper is not a callable * @throws InvalidArgumentException if $helper is not a callable
*/ */
public function __set($name ,$helper) public function __set($name ,$helper)
{ {

View File

@ -8,12 +8,15 @@
* @category Xamin * @category Xamin
* @package Handlebars * @package Handlebars
* @author fzerorubigd <fzerorubigd@gmail.com> * @author fzerorubigd <fzerorubigd@gmail.com>
* @author Behrooz Shabani <everplays@gmail.com>
* @copyright 2012 (c) ParsPooyesh Co * @copyright 2012 (c) ParsPooyesh Co
* @copyright 2013 (c) Behrooz Shabani
* @license MIT <http://opensource.org/licenses/MIT> * @license MIT <http://opensource.org/licenses/MIT>
* @version GIT: $Id$ * @version GIT: $Id$
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars;
/** /**
* Handlebars loader interface * Handlebars loader interface
@ -26,7 +29,6 @@
* @version Release: @package_version@ * @version Release: @package_version@
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars;
interface Loader interface Loader
{ {
@ -39,4 +41,5 @@ interface Loader
* @return String * @return String
*/ */
public function load($name); public function load($name);
} }

View File

@ -9,12 +9,18 @@
* @category Xamin * @category Xamin
* @package Handlebars * @package Handlebars
* @author fzerorubigd <fzerorubigd@gmail.com> * @author fzerorubigd <fzerorubigd@gmail.com>
* @author Behrooz Shabani <everplays@gmail.com>
* @copyright 2012 (c) ParsPooyesh Co * @copyright 2012 (c) ParsPooyesh Co
* @copyright 2013 (c) Behrooz Shabani
* @license MIT <http://opensource.org/licenses/MIT> * @license MIT <http://opensource.org/licenses/MIT>
* @version GIT: $Id$ * @version GIT: $Id$
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars\Loader;
use Handlesbars\Loader;
use Handlesbars\String;
/** /**
* Handlebars Template filesystem Loader implementation. * Handlebars Template filesystem Loader implementation.
* *
@ -27,8 +33,6 @@
* @link http://xamin.ir * * @link http://xamin.ir *
* @implements Loader * @implements Loader
*/ */
namespace Handlebars\Loader;
use Handlesbars\String;
class FilesystemLoader implements Loader class FilesystemLoader implements Loader
{ {
@ -40,10 +44,10 @@ class FilesystemLoader implements Loader
/** /**
* Handlebars filesystem Loader constructor. * Handlebars filesystem Loader constructor.
* *
* Passing an $options array allows overriding certain Loader options during instantiation: * $options array allows overriding certain Loader options during instantiation:
* *
* $options = array( * $options = array(
* // The filename extension used for Handlebars templates. Defaults to '.handlebars' * // extension used for Handlebars templates. Defaults to '.handlebars'
* 'extension' => '.other', * 'extension' => '.other',
* ); * );
* *
@ -66,7 +70,9 @@ class FilesystemLoader implements Loader
foreach ($this->_baseDir as $dir) { foreach ($this->_baseDir as $dir) {
if (!is_dir($dir)) { if (!is_dir($dir)) {
throw new \RuntimeException('FilesystemLoader baseDir must be a directory: ' . $dir); throw new \RuntimeException(
'FilesystemLoader baseDir must be a directory: ' . $dir
);
} }
} }
@ -83,7 +89,8 @@ class FilesystemLoader implements Loader
* Load a Template by name. * Load a Template by name.
* *
* $loader = new FilesystemLoader(dirname(__FILE__).'/views'); * $loader = new FilesystemLoader(dirname(__FILE__).'/views');
* $loader->load('admin/dashboard'); // loads "./views/admin/dashboard.handlebars"; * // loads "./views/admin/dashboard.handlebars";
* $loader->load('admin/dashboard');
* *
* @param string $name template name * @param string $name template name
* *
@ -136,8 +143,9 @@ class FilesystemLoader implements Loader
$fileParts[] = $file; $fileParts[] = $file;
$fileName .= implode('/', $fileParts); $fileName .= implode('/', $fileParts);
$lastCharacters = substr($fileName, 0 - strlen($this->_extension));
if (substr($fileName, 0 - strlen($this->_extension)) !== $this->_extension) { if ($lastCharacters !== $this->_extension) {
$fileName .= $this->_extension; $fileName .= $this->_extension;
} }
if (file_exists($fileName)) { if (file_exists($fileName)) {
@ -147,4 +155,5 @@ class FilesystemLoader implements Loader
} }
return $fileName; return $fileName;
} }
} }

View File

@ -8,12 +8,18 @@
* @category Xamin * @category Xamin
* @package Handlebars * @package Handlebars
* @author fzerorubigd <fzerorubigd@gmail.com> * @author fzerorubigd <fzerorubigd@gmail.com>
* @author Behrooz Shabani <everplays@gmail.com>
* @copyright 2012 (c) ParsPooyesh Co * @copyright 2012 (c) ParsPooyesh Co
* @copyright 2013 (c) Behrooz Shabani
* @license MIT <http://opensource.org/licenses/MIT> * @license MIT <http://opensource.org/licenses/MIT>
* @version GIT: $Id$ * @version GIT: $Id$
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars\Loader;
use Handlebars\Loader;
use Handlebars\String;
/** /**
* Handlebars Template string Loader implementation. * Handlebars Template string Loader implementation.
* *
@ -26,9 +32,6 @@
* @link http://xamin.ir * * @link http://xamin.ir *
* @implements Loader * @implements Loader
*/ */
namespace Handlebars\Loader;
use Handlebars\Loader;
use Handlebars\String;
class StringLoader implements Loader class StringLoader implements Loader
{ {
@ -44,4 +47,5 @@ class StringLoader implements Loader
{ {
return new String($name); return new String($name);
} }
} }

View File

@ -9,15 +9,21 @@
* @category Xamin * @category Xamin
* @package Handlebars * @package Handlebars
* @author fzerorubigd <fzerorubigd@gmail.com> * @author fzerorubigd <fzerorubigd@gmail.com>
* @author Behrooz Shabani <everplays@gmail.com>
* @copyright 2012 (c) ParsPooyesh Co * @copyright 2012 (c) ParsPooyesh Co
* @copyright 2013 (c) Behrooz Shabani
* @license MIT <http://opensource.org/licenses/MIT> * @license MIT <http://opensource.org/licenses/MIT>
* @version GIT: $Id$ * @version GIT: $Id$
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars;
/** /**
* Handlebars parser (infact its a mustache parser) * Handlebars parser (based on mustache)
* This class is responsible for turning raw template source into a set of Mustache tokens. *
* This class is responsible for turning raw template source into a set of
* Handlebars tokens.
* *
* @category Xamin * @category Xamin
* @package Handlebars * @package Handlebars
@ -27,7 +33,6 @@
* @version Release: @package_version@ * @version Release: @package_version@
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars;
class Parser class Parser
{ {
@ -50,7 +55,8 @@ class Parser
* *
* @return array Token parse tree * @return array Token parse tree
* *
* @throws LogicException when nesting errors or mismatched section tags are encountered. * @throws LogicException when nesting errors or mismatched section tags
* are encountered.
*/ */
private function _buildTree(\ArrayIterator $tokens) private function _buildTree(\ArrayIterator $tokens)
{ {
@ -70,7 +76,9 @@ class Parser
do { do {
$result = array_pop($stack); $result = array_pop($stack);
if ($result === null) { if ($result === null) {
throw new \LogicException('Unexpected closing tag: /'. $token[Tokenizer::NAME]); throw new \LogicException(
'Unexpected closing tag: /'. $token[Tokenizer::NAME]
);
} }
if (!array_key_exists(Tokenizer::NODES, $result) if (!array_key_exists(Tokenizer::NODES, $result)
@ -96,4 +104,5 @@ class Parser
return $stack; return $stack;
} }
} }

View File

@ -7,12 +7,14 @@
* @category Xamin * @category Xamin
* @package Handlebars * @package Handlebars
* @author fzerorubigd <fzerorubigd@gmail.com> * @author fzerorubigd <fzerorubigd@gmail.com>
* @author Behrooz Shabani <everplays@gmail.com>
* @copyright 2013 Authors * @copyright 2013 Authors
* @license MIT <http://opensource.org/licenses/MIT> * @license MIT <http://opensource.org/licenses/MIT>
* @version GIT: $Id$ * @version GIT: $Id$
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars;
/** /**
* Handlebars string * Handlebars string
@ -25,7 +27,6 @@
* @version Release: @package_version@ * @version Release: @package_version@
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars;
class String class String
{ {
@ -72,4 +73,5 @@ class String
{ {
$this->_string = $string; $this->_string = $string;
} }
} }

View File

@ -8,12 +8,15 @@
* @category Xamin * @category Xamin
* @package Handlebars * @package Handlebars
* @author fzerorubigd <fzerorubigd@gmail.com> * @author fzerorubigd <fzerorubigd@gmail.com>
* @author Behrooz Shabani <everplays@gmail.com>
* @copyright 2012 (c) ParsPooyesh Co * @copyright 2012 (c) ParsPooyesh Co
* @copyright 2013 (c) Behrooz Shabani
* @license MIT <http://opensource.org/licenses/MIT> * @license MIT <http://opensource.org/licenses/MIT>
* @version GIT: $Id$ * @version GIT: $Id$
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars;
/** /**
* Handlebars base template * Handlebars base template
@ -27,7 +30,6 @@
* @version Release: @package_version@ * @version Release: @package_version@
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars;
class Template class Template
{ {
@ -50,8 +52,8 @@ class Template
* Handlebars template constructor * Handlebars template constructor
* *
* @param Handlebars $engine handlebar engine * @param Handlebars $engine handlebar engine
* @param array $tree Parsed tree * @param array $tree Parsed tree
* @param string $source Handlebars source * @param string $source Handlebars source
*/ */
public function __construct(Handlebars $engine, $tree, $source) public function __construct(Handlebars $engine, $tree, $source)
{ {
@ -129,7 +131,7 @@ class Template
if (!$context instanceof Context) { if (!$context instanceof Context) {
$context = new Context($context); $context = new Context($context);
} }
$topTree = end($this->_stack); //This method (render) never pop a value from stack $topTree = end($this->_stack); // never pop a value from stack
list($index ,$tree, $stop) = $topTree; list($index ,$tree, $stop) = $topTree;
$buffer = ''; $buffer = '';
@ -145,13 +147,15 @@ class Template
} }
switch ($current[Tokenizer::TYPE]) { switch ($current[Tokenizer::TYPE]) {
case Tokenizer::T_SECTION : case Tokenizer::T_SECTION :
$newStack = isset($current[Tokenizer::NODES]) ? $current[Tokenizer::NODES] : array(); $newStack = isset($current[Tokenizer::NODES])
? $current[Tokenizer::NODES] : array();
array_push($this->_stack, array(0, $newStack, false)); array_push($this->_stack, array(0, $newStack, false));
$buffer .= $this->_section($context, $current); $buffer .= $this->_section($context, $current);
array_pop($this->_stack); array_pop($this->_stack);
break; break;
case Tokenizer::T_INVERTED : case Tokenizer::T_INVERTED :
$newStack = isset($current[Tokenizer::NODES]) ? $current[Tokenizer::NODES] : array(); $newStack = isset($current[Tokenizer::NODES]) ?
$current[Tokenizer::NODES] : array();
array_push($this->_stack, array(0, $newStack, false)); array_push($this->_stack, array(0, $newStack, false));
$buffer .= $this->_inverted($context, $current); $buffer .= $this->_inverted($context, $current);
array_pop($this->_stack); array_pop($this->_stack);
@ -174,7 +178,9 @@ class Template
$buffer .= $current[Tokenizer::VALUE]; $buffer .= $current[Tokenizer::VALUE];
break; break;
default: default:
throw new \RuntimeException('Invalid node type : ' . json_encode($current)); throw new \RuntimeException(
'Invalid node type : ' . json_encode($current)
);
} }
} }
if ($stop) { if ($stop) {
@ -226,7 +232,7 @@ class Template
* Process section nodes * Process section nodes
* *
* @param Context $context current context * @param Context $context current context
* @param array $current section node data * @param array $current section node data
* *
* @return string the result * @return string the result
*/ */
@ -258,11 +264,14 @@ class Template
return $return; return $return;
} }
} elseif (trim($current[Tokenizer::ARGS]) == '') { } elseif (trim($current[Tokenizer::ARGS]) == '') {
//Fallback for mustache style each/with/for just if there is no argument at all. // fallback to mustache style each/with/for just if there is
// no argument at all.
try { try {
$sectionVar = $context->get($sectionName, true); $sectionVar = $context->get($sectionName, true);
} catch (InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
throw new \RuntimeException($sectionName . ' is not registered as a helper'); throw new \RuntimeException(
$sectionName . ' is not registered as a helper'
);
} }
$buffer = ''; $buffer = '';
if (is_array($sectionVar) || $sectionVar instanceof Traversable) { if (is_array($sectionVar) || $sectionVar instanceof Traversable) {
@ -283,7 +292,9 @@ class Template
} }
return $buffer; return $buffer;
} else { } else {
throw new \RuntimeException($sectionName . ' is not registered as a helper'); throw new \RuntimeException(
$sectionName . ' is not registered as a helper'
);
} }
} }
@ -291,7 +302,7 @@ class Template
* Process inverted section * Process inverted section
* *
* @param Context $context current context * @param Context $context current context
* @param array $current section node data * @param array $current section node data
* *
* @return string the result * @return string the result
*/ */
@ -311,7 +322,7 @@ class Template
* Process partial section * Process partial section
* *
* @param Context $context current context * @param Context $context current context
* @param array $current section node data * @param array $current section node data
* *
* @return string the result * @return string the result
*/ */
@ -330,8 +341,8 @@ class Template
* Process partial section * Process partial section
* *
* @param Context $context current context * @param Context $context current context
* @param array $current section node data * @param array $current section node data
* @param boolean $escaped escape result or not * @param boolean $escaped escape result or not
* *
* @return string the result * @return string the result
*/ */
@ -339,19 +350,21 @@ class Template
{ {
$name = $current[Handlebars_Tokenizer::NAME]; $name = $current[Handlebars_Tokenizer::NAME];
$value = $context->get($name); $value = $context->get($name);
if( $name == '@index' ) { if ( $name == '@index' ) {
return $context->lastIndex(); return $context->lastIndex();
} }
if( $name == '@key' ) { if ( $name == '@key' ) {
return $context->lastKey(); return $context->lastKey();
} }
if ($escaped) { if ($escaped) {
$args = $this->handlebars->getEscapeArgs(); $args = $this->handlebars->getEscapeArgs();
array_unshift($args, $value); array_unshift($args, $value);
$value = call_user_func_array($this->handlebars->getEscape(), array_values($args)); $value = call_user_func_array(
$this->handlebars->getEscape(),
array_values($args)
);
} }
return $value; return $value;
} }
} }

View File

@ -11,17 +11,18 @@
* @package Handlebars * @package Handlebars
* @author Justin Hileman <dontknow@example.org> * @author Justin Hileman <dontknow@example.org>
* @author fzerorubigd <fzerorubigd@gmail.com> * @author fzerorubigd <fzerorubigd@gmail.com>
* @copyright 2012 Justin Hileman * @author Behrooz Shabani <everplays@gmail.com>
* @copyright 2012 (c) ParsPooyesh Co
* @copyright 2013 (c) Behrooz Shabani
* @license MIT <http://opensource.org/licenses/mit-license.php> * @license MIT <http://opensource.org/licenses/mit-license.php>
* @version GIT: $Id$ * @version GIT: $Id$
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars;
/** /**
* Handlebars parser (infact its a mustache parser) * Handlebars tokenizer (based on mustache)
* This class is responsible for turning raw template source into a set of Mustache tokens.
* Some minor changes to handle Handlebars instead of Mustache
* *
* @category Xamin * @category Xamin
* @package Handlebars * @package Handlebars
@ -32,7 +33,6 @@
* @version Release: @package_version@ * @version Release: @package_version@
* @link http://xamin.ir * @link http://xamin.ir
*/ */
namespace Handlebars;
class Tokenizer class Tokenizer
{ {
@ -47,7 +47,8 @@ class Tokenizer
const T_INVERTED = '^'; const T_INVERTED = '^';
const T_END_SECTION = '/'; const T_END_SECTION = '/';
const T_COMMENT = '!'; const T_COMMENT = '!';
const T_PARTIAL = '>'; //Maybe remove this partials and replace them with helpers // XXX: remove partials support from tokenizer and make it a helper?
const T_PARTIAL = '>';
const T_PARTIAL_2 = '<'; const T_PARTIAL_2 = '<';
const T_DELIM_CHANGE = '='; const T_DELIM_CHANGE = '=';
const T_ESCAPED = '_v'; const T_ESCAPED = '_v';
@ -102,7 +103,7 @@ class Tokenizer
* Scan and tokenize template source. * Scan and tokenize template source.
* *
* @param string $text Mustache template source to tokenize * @param string $text Mustache template source to tokenize
* @param string $delimiters Optionally, pass initial opening and closing delimiters (default: null) * @param string $delimiters Optional, pass opening and closing delimiters
* *
* @return array Set of Mustache tokens * @return array Set of Mustache tokens
*/ */
@ -163,8 +164,7 @@ class Tokenizer
if ($this->tagChange($this->ctag, $text, $i)) { if ($this->tagChange($this->ctag, $text, $i)) {
// Sections (Helpers) can accept parameters // Sections (Helpers) can accept parameters
// Same thing for Partials (little known fact) // Same thing for Partials (little known fact)
if ( if ( ($this->tagType == self::T_SECTION)
($this->tagType == self::T_SECTION)
|| ($this->tagType == self::T_PARTIAL) || ($this->tagType == self::T_PARTIAL)
|| ($this->tagType == self::T_PARTIAL_2) || ($this->tagType == self::T_PARTIAL_2)
) { ) {
@ -180,7 +180,9 @@ class Tokenizer
self::NAME => trim($this->buffer), self::NAME => trim($this->buffer),
self::OTAG => $this->otag, self::OTAG => $this->otag,
self::CTAG => $this->ctag, self::CTAG => $this->ctag,
self::INDEX => ($this->tagType == self::T_END_SECTION) ? $this->seenTag - strlen($this->otag) : $i + strlen($this->ctag), self::INDEX => ($this->tagType == self::T_END_SECTION) ?
$this->seenTag - strlen($this->otag) :
$i + strlen($this->ctag),
); );
if (isset($args)) { if (isset($args)) {
$t[self::ARGS] = $args; $t[self::ARGS] = $args;
@ -196,9 +198,12 @@ class Tokenizer
$i++; $i++;
} else { } else {
// Clean up `{{{ tripleStache }}}` style tokens. // Clean up `{{{ tripleStache }}}` style tokens.
$lastName = $this->tokens[count($this->tokens) - 1][self::NAME]; $lastIndex = count($this->tokens) - 1;
$lastName = $this->tokens[$lastIndex][self::NAME];
if (substr($lastName, -1) === '}') { if (substr($lastName, -1) === '}') {
$this->tokens[count($this->tokens) - 1][self::NAME] = trim(substr($lastName, 0, -1)); $this->tokens[$lastIndex][self::NAME] = trim(
substr($lastName, 0, -1)
);
} }
} }
} }
@ -240,7 +245,10 @@ class Tokenizer
protected function flushBuffer() protected function flushBuffer()
{ {
if (!empty($this->buffer)) { if (!empty($this->buffer)) {
$this->tokens[] = array(self::TYPE => self::T_TEXT, self::VALUE => $this->buffer); $this->tokens[] = array(
self::TYPE => self::T_TEXT,
self::VALUE => $this->buffer
);
$this->buffer = ''; $this->buffer = '';
} }
} }
@ -283,8 +291,11 @@ class Tokenizer
$tokensCount = count($this->tokens); $tokensCount = count($this->tokens);
for ($j = $this->lineStart; $j < $tokensCount; $j++) { for ($j = $this->lineStart; $j < $tokensCount; $j++) {
if ($this->tokens[$j][self::TYPE] == self::T_TEXT) { if ($this->tokens[$j][self::TYPE] == self::T_TEXT) {
if (isset($this->tokens[$j + 1]) && $this->tokens[$j + 1][self::TYPE] == self::T_PARTIAL) { if (isset($this->tokens[$j + 1])
$this->tokens[$j + 1][self::INDENT] = $this->tokens[$j][self::VALUE]; && $this->tokens[$j + 1][self::TYPE] == self::T_PARTIAL
) {
$this->tokens[$j + 1][self::INDENT]
= $this->tokens[$j][self::VALUE];
} }
$this->tokens[$j] = null; $this->tokens[$j] = null;
@ -312,7 +323,10 @@ class Tokenizer
$close = '='.$this->ctag; $close = '='.$this->ctag;
$closeIndex = strpos($text, $close, $index); $closeIndex = strpos($text, $close, $index);
list($otag, $ctag) = explode(' ', trim(substr($text, $startIndex, $closeIndex - $startIndex))); list($otag, $ctag) = explode(
' ',
trim(substr($text, $startIndex, $closeIndex - $startIndex))
);
$this->otag = $otag; $this->otag = $otag;
$this->ctag = $ctag; $this->ctag = $ctag;
@ -332,4 +346,5 @@ class Tokenizer
{ {
return substr($text, $index, strlen($tag)) === $tag; return substr($text, $index, strlen($tag)) === $tag;
} }
} }