Merge pull request #123 from Zemistr/master

Added support for class with __toString method as a context variable.
This commit is contained in:
fzerorubigd 2015-06-08 09:26:41 +04:30
commit 959834be09
2 changed files with 12 additions and 3 deletions

View File

@ -591,14 +591,14 @@ class Template
}
if ($escaped) {
$args = $this->handlebars->getEscapeArgs();
array_unshift($args, $value);
array_unshift($args, (string)$value);
$value = call_user_func_array(
$this->handlebars->getEscape(),
array_values($args)
);
}
return $value;
return (string)$value;
}
/**

View File

@ -757,6 +757,9 @@ EOM;
// Reference array as string
$this->assertEquals('Array', $engine->render('{{var}}', array('var' => array('test'))));
// Test class with __toString method
$this->assertEquals('test', $engine->render('{{var}}', array('var' => new TestClassWithToStringMethod())));
$obj = new DateTime();
$time = $obj->getTimestamp();
$this->assertEquals($time, $engine->render('{{time.getTimestamp}}', array('time' => $obj)));
@ -1270,6 +1273,12 @@ EOM;
}
class TestClassWithToStringMethod {
public function __toString() {
return 'test';
}
}
/**
* Testcase for testInlineLoader
*
@ -1282,4 +1291,4 @@ This is a inline template.
a
b
c
d
d