case for the right String Class

Not sure where i got StringWrapper from. We now don’t need to case for
this in the `registerHelper()` method
This commit is contained in:
Christian Blanquera 2015-09-26 20:03:52 +08:00
parent 1ba7cdf108
commit 08ad533e81
2 changed files with 1 additions and 31 deletions

View File

@ -268,7 +268,7 @@ class Handlebars
foreach ($args as $i => $arg) {
//if it's literally string
if ($arg instanceof StringWrapper) {
if ($arg instanceof BaseString) {
//we have no problems here
$args[$i] = (string) $arg;
continue;

View File

@ -485,21 +485,6 @@ class HandlebarsTest extends \PHPUnit_Framework_TestCase
//create a better if helper
$engine->registerHelper('when', function($value1, $operator, $value2, $options) {
//make sure value 1 is scalar
if(is_object($value1) && method_exists($value1, '__toString')) {
$value1 = (string) $value1;
}
//make sure operator is scalar
if(is_object($operator) && method_exists($operator, '__toString')) {
$operator = (string) $operator;
}
//make sure value 2 is scalar
if(is_object($value2) && method_exists($value2, '__toString')) {
$value2 = (string) $value2;
}
$valid = false;
//the amazing reverse switch!
switch (true) {
@ -560,11 +545,6 @@ class HandlebarsTest extends \PHPUnit_Framework_TestCase
//array in
$engine->registerHelper('in', function(array $array, $key, $options) {
//make sure key is scalar
if(is_object($key) && method_exists($key, '__toString')) {
$key = (string) $key;
}
if(in_array($key, $array)) {
return $options['fn']();
}
@ -574,16 +554,6 @@ class HandlebarsTest extends \PHPUnit_Framework_TestCase
//converts date formats to other formats
$engine->registerHelper('date', function($time, $format, $options) {
//make sure time is scalar
if(is_object($time) && method_exists($time, '__toString')) {
$time = (string) $time;
}
//make sure format is scalar
if(is_object($format) && method_exists($format, '__toString')) {
$format = (string) $format;
}
return date($format, strtotime($time));
});