mirror of
https://github.com/Mibew/handlebars.php.git
synced 2025-05-03 10:33:08 +03:00
Make the fix for #105 more elegant, using $template->parseArguments()
This commit is contained in:
parent
2b3d450849
commit
84b3031a44
@ -50,15 +50,8 @@ class IfHelper implements Helper
|
|||||||
*/
|
*/
|
||||||
public function execute(Template $template, Context $context, $args, $source)
|
public function execute(Template $template, Context $context, $args, $source)
|
||||||
{
|
{
|
||||||
if (is_numeric($args)) {
|
$parsedArgs = $template->parseArguments($args);
|
||||||
$tmp = $args;
|
$tmp = $context->get($parsedArgs[0]);
|
||||||
} 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());
|
$context->push($context->last());
|
||||||
if ($tmp) {
|
if ($tmp) {
|
||||||
|
@ -50,15 +50,8 @@ class UnlessHelper implements Helper
|
|||||||
*/
|
*/
|
||||||
public function execute(Template $template, Context $context, $args, $source)
|
public function execute(Template $template, Context $context, $args, $source)
|
||||||
{
|
{
|
||||||
if (is_numeric($args)) {
|
$parsedArgs = $template->parseArguments($args);
|
||||||
$tmp = $args;
|
$tmp = $context->get($parsedArgs[0]);
|
||||||
} 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());
|
$context->push($context->last());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user