mirror of
https://github.com/Mibew/handlebars.php.git
synced 2025-05-02 18:26:40 +03:00
Helpers: Added PHP 5.2 support.
This commit is contained in:
parent
8eb732f407
commit
6ea602c9c9
@ -59,16 +59,19 @@ class Handlebars_Helpers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add default helpers (if unless each with)
|
* Create handler for the 'if' helper.
|
||||||
|
* Needed for compatibility with PHP 5.2 since it doesn't support anonymous functions.
|
||||||
*
|
*
|
||||||
* @return void
|
* @param $template
|
||||||
|
* @param $context
|
||||||
|
* @param $args
|
||||||
|
* @param $source
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
protected function addDefaultHelpers()
|
public static function _helper_if($template, $context, $args, $source) {
|
||||||
{
|
|
||||||
$this->add(
|
|
||||||
'if',
|
|
||||||
function ($template, $context, $args, $source) {
|
|
||||||
$tmp = $context->get($args);
|
$tmp = $context->get($args);
|
||||||
$buffer = '';
|
$buffer = '';
|
||||||
|
|
||||||
@ -85,11 +88,19 @@ class Handlebars_Helpers
|
|||||||
}
|
}
|
||||||
return $buffer;
|
return $buffer;
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
$this->add(
|
/**
|
||||||
'each',
|
* Create handler for the 'each' helper.
|
||||||
function ($template, $context, $args, $source) {
|
* Needed for compatibility with PHP 5.2 since it doesn't support anonymous functions.
|
||||||
|
*
|
||||||
|
* @param $template
|
||||||
|
* @param $context
|
||||||
|
* @param $args
|
||||||
|
* @param $source
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function _helper_each($template, $context, $args, $source) {
|
||||||
$tmp = $context->get($args);
|
$tmp = $context->get($args);
|
||||||
$buffer = '';
|
$buffer = '';
|
||||||
if (is_array($tmp) || $tmp instanceof Traversable) {
|
if (is_array($tmp) || $tmp instanceof Traversable) {
|
||||||
@ -101,11 +112,19 @@ class Handlebars_Helpers
|
|||||||
}
|
}
|
||||||
return $buffer;
|
return $buffer;
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
$this->add(
|
/**
|
||||||
'unless',
|
* Create handler for the 'unless' helper.
|
||||||
function ($template, $context, $args, $source) {
|
* Needed for compatibility with PHP 5.2 since it doesn't support anonymous functions.
|
||||||
|
*
|
||||||
|
* @param $template
|
||||||
|
* @param $context
|
||||||
|
* @param $args
|
||||||
|
* @param $source
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function _helper_unless($template, $context, $args, $source) {
|
||||||
$tmp = $context->get($args);
|
$tmp = $context->get($args);
|
||||||
$buffer = '';
|
$buffer = '';
|
||||||
if (!$tmp) {
|
if (!$tmp) {
|
||||||
@ -113,25 +132,72 @@ class Handlebars_Helpers
|
|||||||
}
|
}
|
||||||
return $buffer;
|
return $buffer;
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
$this->add(
|
/**
|
||||||
'with',
|
* Create handler for the 'with' helper.
|
||||||
function ($template, $context, $args, $source) {
|
* Needed for compatibility with PHP 5.2 since it doesn't support anonymous functions.
|
||||||
|
*
|
||||||
|
* @param $template
|
||||||
|
* @param $context
|
||||||
|
* @param $args
|
||||||
|
* @param $source
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function _helper_with($template, $context, $args, $source) {
|
||||||
$tmp = $context->get($args);
|
$tmp = $context->get($args);
|
||||||
$context->push($tmp);
|
$context->push($tmp);
|
||||||
$buffer = $template->render($context);
|
$buffer = $template->render($context);
|
||||||
$context->pop();
|
$context->pop();
|
||||||
return $buffer;
|
return $buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create handler for the 'bindAttr' helper.
|
||||||
|
* Needed for compatibility with PHP 5.2 since it doesn't support anonymous functions.
|
||||||
|
*
|
||||||
|
* @param $template
|
||||||
|
* @param $context
|
||||||
|
* @param $args
|
||||||
|
* @param $source
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function _helper_bindAttr($template, $context, $args, $source) {
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add default helpers (if unless each with bindAttr)
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function addDefaultHelpers()
|
||||||
|
{
|
||||||
|
$this->add(
|
||||||
|
'if',
|
||||||
|
array('Handlebars_Helpers', '_helper_if')
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->add(
|
||||||
|
'each',
|
||||||
|
array('Handlebars_Helpers', '_helper_each')
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->add(
|
||||||
|
'unless',
|
||||||
|
array('Handlebars_Helpers', '_helper_unless')
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->add(
|
||||||
|
'with',
|
||||||
|
array('Handlebars_Helpers', '_helper_with')
|
||||||
);
|
);
|
||||||
|
|
||||||
//Just for compatibility with ember
|
//Just for compatibility with ember
|
||||||
$this->add(
|
$this->add(
|
||||||
'bindAttr',
|
'bindAttr',
|
||||||
function ($template, $context, $args, $source) {
|
array('Handlebars_Helpers', '_helper_bindAttr')
|
||||||
return $args;
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user