mirror of
				https://github.com/Mibew/handlebars.php.git
				synced 2025-11-04 04:05:07 +03:00 
			
		
		
		
	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:
		
							parent
							
								
									1ba7cdf108
								
							
						
					
					
						commit
						08ad533e81
					
				@ -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;
 | 
			
		||||
 | 
			
		||||
@ -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));
 | 
			
		||||
        });
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user