mirror of
				https://github.com/Mibew/handlebars.php.git
				synced 2025-11-04 04:05:07 +03:00 
			
		
		
		
	Add ability to merge Helpers collections
This commit is contained in:
		
							parent
							
								
									ed57d8f7d7
								
							
						
					
					
						commit
						e8ce548b86
					
				@ -106,6 +106,21 @@ class Helpers
 | 
			
		||||
        $this->helpers[$name] = $helper;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Add all helpers from the specified collection to the current one.
 | 
			
		||||
     *
 | 
			
		||||
     * The method will override helpers from the current collections with same
 | 
			
		||||
     * named helpers from the specified collection.
 | 
			
		||||
     *
 | 
			
		||||
     * @param Helpers $helpers A collection which helpers should be added.
 | 
			
		||||
     *
 | 
			
		||||
     * @return void
 | 
			
		||||
     */
 | 
			
		||||
    public function addHelpers(Helpers $helpers)
 | 
			
		||||
    {
 | 
			
		||||
        $this->helpers = $helpers->getAll() + $this->helpers;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Calls a helper, whether it be a Closure or Helper instance
 | 
			
		||||
     *
 | 
			
		||||
@ -238,4 +253,15 @@ class Helpers
 | 
			
		||||
    {
 | 
			
		||||
        return empty($this->helpers);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns all helpers from the collection.
 | 
			
		||||
     *
 | 
			
		||||
     * @return array Associative array of helpers which keys are helpers names
 | 
			
		||||
     * and the values are the helpers.
 | 
			
		||||
     */
 | 
			
		||||
    public function getAll()
 | 
			
		||||
    {
 | 
			
		||||
        return $this->helpers;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -487,7 +487,7 @@ class HandlebarsTest extends \PHPUnit_Framework_TestCase
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Test add/get/has/clear functions on helper class
 | 
			
		||||
     * Test add/addHelpers/get/getAll/has/clear functions on helper class
 | 
			
		||||
     */
 | 
			
		||||
    public function testHelpersClass()
 | 
			
		||||
    {
 | 
			
		||||
@ -509,6 +509,14 @@ class HandlebarsTest extends \PHPUnit_Framework_TestCase
 | 
			
		||||
        $this->assertFalse($helpers->has('test'));
 | 
			
		||||
        $this->assertFalse(isset($helpers->test));
 | 
			
		||||
        $this->assertTrue($helpers->isEmpty());
 | 
			
		||||
        $helpers->add('test', function() {});
 | 
			
		||||
        $this->assertCount(0, array_diff(array_keys($helpers->getAll()), array('test')));
 | 
			
		||||
        $extraHelpers = new \Handlebars\Helpers();
 | 
			
		||||
        $extraHelpers->add('test', function() {});
 | 
			
		||||
        $extraHelpers->add('test2', function() {});
 | 
			
		||||
        $helpers->addHelpers($extraHelpers);
 | 
			
		||||
        $this->assertTrue($helpers->has('test2'));
 | 
			
		||||
        $this->assertEquals($helpers->test, $extraHelpers->test);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user