From 08ad533e815374080ddd6acb311a2e74ce2f3a66 Mon Sep 17 00:00:00 2001 From: Christian Blanquera Date: Sat, 26 Sep 2015 20:03:52 +0800 Subject: [PATCH] case for the right String Class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not sure where i got StringWrapper from. We now don’t need to case for this in the `registerHelper()` method --- src/Handlebars/Handlebars.php | 2 +- tests/Xamin/HandlebarsTest.php | 30 ------------------------------ 2 files changed, 1 insertion(+), 31 deletions(-) diff --git a/src/Handlebars/Handlebars.php b/src/Handlebars/Handlebars.php index b0513eb..77aac5b 100755 --- a/src/Handlebars/Handlebars.php +++ b/src/Handlebars/Handlebars.php @@ -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; diff --git a/tests/Xamin/HandlebarsTest.php b/tests/Xamin/HandlebarsTest.php index 31b2177..8edaf66 100644 --- a/tests/Xamin/HandlebarsTest.php +++ b/tests/Xamin/HandlebarsTest.php @@ -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)); });