Skip to content

Commit

Permalink
Make function will make key when called wo params
Browse files Browse the repository at this point in the history
  • Loading branch information
jm42 committed Jun 29, 2017
1 parent 64cfc5d commit 1f4081b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### 0.13.0

- [BC-BREAK] Factory call to make without parameters gets service from it's own instead of delegate.
- [BC-BREAK] Factory call to make without parameters use make of key class.
- [BC-BREAK] Call a function will resolve parameters from it's own instead of delegate.
- [BC-BREAK] Resolve parameters default values.

Expand Down
2 changes: 1 addition & 1 deletion library/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function(string $dep=null, array $args=[]) use($key) {
// $dep should be a concrete class or null
// $key could be abstract or interface
if (is_null($dep) && empty($args)) {
return $this[$key];
return $this->make($key);
}
return $this->make($dep, $args);
}
Expand Down
5 changes: 2 additions & 3 deletions spec/Suite/RegistrySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,11 @@ function __construct(Engine $engine, string $color='red') {

it('calls factory with make function that when called without parameters it creates an instance of the abstract', function() {
$di = new Registry;
$di->offsetSet(Engine::class, V8::class);
$di->offsetSet(Engine::class, function($c, $make) {
$di->offsetSet(V8::class, function($c, $make) {
return $make();
});

expect($di->offsetGet(Engine::class))->toBeAnInstanceOf(V8::class);
expect($di->offsetGet(V8::class))->toBeAnInstanceOf(V8::class);
});

it('calls factory and resolve parameters', function() {
Expand Down

0 comments on commit 1f4081b

Please sign in to comment.