phpcs approval

“oh the spacing!”
This commit is contained in:
Christian Blanquera 2015-09-21 18:49:08 +08:00
parent 33c76738b4
commit 0070ad79c0
2 changed files with 147 additions and 128 deletions

View File

@ -47,10 +47,12 @@ class ChildContext extends Context
* Sets a parent context in which * Sets a parent context in which
* we will case for the ../ in get() * we will case for the ../ in get()
* *
* @param Context * @param Context $parent parent context
*
* @return void * @return void
*/ */
public function setParent(Context $parent) { public function setParent(Context $parent)
{
$this->parentContext = $parent; $this->parentContext = $parent;
} }
@ -71,7 +73,9 @@ class ChildContext extends Context
{ {
//if the variable name starts with a ../ //if the variable name starts with a ../
//and we have a parent //and we have a parent
if(strpos($variableName, '../') === 0 && $this->parentContext instanceof Context) { if (strpos($variableName, '../') === 0
&& $this->parentContext instanceof Context
) {
//just remove the first ../ //just remove the first ../
$variableName = substr($variableName, 3); $variableName = substr($variableName, 3);

View File

@ -39,7 +39,7 @@ class Handlebars
const VERSION = '1.0.0'; const VERSION = '1.0.0';
/** /**
* factory method * Factory method
* *
* @param array $options see __construct's options parameter * @param array $options see __construct's options parameter
* *
@ -55,41 +55,57 @@ class Handlebars
} }
/** /**
* Current tokenizer instance
*
* @var Tokenizer * @var Tokenizer
*/ */
private $_tokenizer; private $_tokenizer;
/** /**
* Current parser instance
*
* @var Parser * @var Parser
*/ */
private $_parser; private $_parser;
/** /**
* Current helper list
*
* @var Helpers * @var Helpers
*/ */
private $_helpers; private $_helpers;
/** /**
* Current loader instance
*
* @var Loader * @var Loader
*/ */
private $_loader; private $_loader;
/** /**
* Current partial loader instance
*
* @var Loader * @var Loader
*/ */
private $_partialsLoader; private $_partialsLoader;
/** /**
* Current cache instance
*
* @var Cache * @var Cache
*/ */
private $_cache; private $_cache;
/** /**
* The escape method
*
* @var callable escape function to use * @var callable escape function to use
*/ */
private $_escape = 'htmlspecialchars'; private $_escape = 'htmlspecialchars';
/** /**
* Parameters for the escpae method above
*
* @var array parametes to pass to escape function * @var array parametes to pass to escape function
*/ */
private $_escapeArgs = array( private $_escapeArgs = array(
@ -246,21 +262,20 @@ class Handlebars
*/ */
public function registerHelper($name, $helper) public function registerHelper($name, $helper)
{ {
$this->addHelper($name, function($template, $context, $arg) use ($helper) $callback = function ($template, $context, $arg) use ($helper) {
{
$args = $template->parseArguments($arg); $args = $template->parseArguments($arg);
$named = $template->parseNamedArguments($arg); $named = $template->parseNamedArguments($arg);
foreach($args as $i => $arg) { foreach ($args as $i => $arg) {
//if it's literally string //if it's literally string
if($arg instanceof StringWrapper) { if ($arg instanceof StringWrapper) {
//we have no problems here //we have no problems here
$args[$i] = (string) $arg; $args[$i] = (string) $arg;
continue; continue;
} }
//not sure what to do if it's not a string or StringWrapper //not sure what to do if it's not a string or StringWrapper
if(!is_string($arg)) { if (!is_string($arg)) {
continue; continue;
} }
@ -279,11 +294,10 @@ class Handlebars
// Named arguments // Named arguments
'hash' => $named, 'hash' => $named,
// A renderer for block helper // A renderer for block helper
'fn' => function($inContext = null) use($context, $template) 'fn' => function ($inContext = null) use ($context, $template) {
{
$defined = !!$inContext; $defined = !!$inContext;
if(!$defined) { if (!$defined) {
$inContext = $context; $inContext = $context;
$inContext->push($inContext->last()); $inContext->push($inContext->last());
} else if (!$inContext instanceof Context) { } else if (!$inContext instanceof Context) {
@ -300,7 +314,7 @@ class Handlebars
//I mean in this context (literally) //I mean in this context (literally)
//$template->discard($inContext); //$template->discard($inContext);
if($defined) { if ($defined) {
$inContext->pop(); $inContext->pop();
} }
@ -308,11 +322,10 @@ class Handlebars
}, },
// A render for the else block // A render for the else block
'inverse' => function($inContext = null) use($context, $template) 'inverse' => function ($inContext = null) use ($context, $template) {
{
$defined = !!$inContext; $defined = !!$inContext;
if(!$defined) { if (!$defined) {
$inContext = $context; $inContext = $context;
$inContext->push($inContext->last()); $inContext->push($inContext->last());
} else if (!$inContext instanceof Context) { } else if (!$inContext instanceof Context) {
@ -325,7 +338,7 @@ class Handlebars
$template->setStopToken(false); $template->setStopToken(false);
$buffer = $template->render($inContext); $buffer = $template->render($inContext);
if($defined) { if ($defined) {
$inContext->pop(); $inContext->pop();
} }
@ -338,7 +351,9 @@ class Handlebars
'template' => $template); 'template' => $template);
return call_user_func_array($helper, $args); return call_user_func_array($helper, $args);
}); };
$this->addHelper($name, $callback);
} }
/** /**
@ -366,7 +381,7 @@ class Handlebars
} }
/** /**
* get current loader * Get current loader
* *
* @return Loader * @return Loader
*/ */
@ -392,7 +407,7 @@ class Handlebars
} }
/** /**
* get current partials loader * Get current partials loader
* *
* @return Loader * @return Loader
*/ */
@ -618,7 +633,7 @@ class Handlebars
} }
/** /**
* try to tokenize source, or get them from cache if available * Try to tokenize source, or get them from cache if available
* *
* @param string $source handlebars source code * @param string $source handlebars source code
* *