Skip to content

Commit

Permalink
[5.4] Container: Extend() can not fire the rebinding callback (#19288)
Browse files Browse the repository at this point in the history
* fix:Extend() can not fire the rebinding callback issue #19241

* StyleCI

* StyleCI

* StyleCI
  • Loading branch information
LeoYang90 authored and taylorotwell committed May 24, 2017
1 parent 10e15da commit 38c6076
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ public function extend($abstract, Closure $closure)
$this->rebound($abstract);
} else {
$this->extenders[$abstract][] = $closure;

if ($this->resolved($abstract)) {
$this->rebound($abstract);
}
}
}

Expand Down
44 changes: 44 additions & 0 deletions tests/Container/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,50 @@ public function testExtendCanBeCalledBeforeBind()
$this->assertEquals('foobar', $container->make('foo'));
}

public function testExtendInstanceRebindingCallback()
{
$_SERVER['_test_rebind'] = false;

$container = new Container;
$container->rebinding('foo', function () {
$_SERVER['_test_rebind'] = true;
});

$obj = new StdClass;
$container->instance('foo', $obj);

$container->extend('foo', function ($obj, $container) {
return $obj;
});

$this->assertTrue($_SERVER['_test_rebind']);
}

public function testExtendBindRebindingCallback()
{
$_SERVER['_test_rebind'] = false;

$container = new Container;
$container->rebinding('foo', function () {
$_SERVER['_test_rebind'] = true;
});
$container->bind('foo', function () {
$obj = new StdClass;

return $obj;
});

$this->assertFalse($_SERVER['_test_rebind']);

$container->make('foo');

$container->extend('foo', function ($obj, $container) {
return $obj;
});

$this->assertTrue($_SERVER['_test_rebind']);
}

public function testUnsetExtend()
{
$container = new Container;
Expand Down

0 comments on commit 38c6076

Please sign in to comment.