Skip to content

Commit

Permalink
Theme container calls callable binding on resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
jedrzejchalubek committed Feb 27, 2017
1 parent 41285f1 commit 15707ee
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Gin/Foundation/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ public function bind($key, $value)
* Resolve value from theme registry.
*
* @param string $key
* @param array $parameters
*
* @return mixed
*/
public function get($key)
public function get($key, $parameters = [])
{
if (is_callable($callable = $this->registry[$key])) {
return call_user_func_array($callable, $parameters);
}

return $this->registry[$key];
}
}
21 changes: 20 additions & 1 deletion tests/Gin/Foundation/ThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,31 @@ public function it_return_same_instance_on_every_access()
/**
* @test
*/
public function test_binding_and_resolving_from_theme_container()
public function test_binding_and_resolving_value_from_theme_container()
{
$theme = Theme::getInstance();

$theme->bind('key', 'value');

$this->assertEquals(Theme::getInstance()->get('key'), 'value');
}

/**
* @test
*/
public function test_binding_and_resolving_closure_from_theme_container()
{
$theme = Theme::getInstance();

$theme->bind('key.without.parameters', function () {
return 'value';
});

$theme->bind('key.with.parameters', function ($param1, $param2) {
return $param1.','.$param2;
});

$this->assertEquals(Theme::getInstance()->get('key.without.parameters'), 'value');
$this->assertEquals(Theme::getInstance()->get('key.with.parameters', ['value1', 'value2']), 'value1,value2');
}
}

0 comments on commit 15707ee

Please sign in to comment.