From cb1257ac337de7f7fef64872d77cec1c5587eb13 Mon Sep 17 00:00:00 2001 From: leoyang90 Date: Thu, 18 May 2017 16:32:20 +0800 Subject: [PATCH 1/4] fix:Extend() can not fire the rebinding callback issue #19241 --- src/Illuminate/Container/Container.php | 3 +++ tests/Container/ContainerTest.php | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/Illuminate/Container/Container.php b/src/Illuminate/Container/Container.php index 5e518174f563..5d4a9417f6cd 100755 --- a/src/Illuminate/Container/Container.php +++ b/src/Illuminate/Container/Container.php @@ -343,6 +343,9 @@ public function extend($abstract, Closure $closure) $this->rebound($abstract); } else { $this->extenders[$abstract][] = $closure; + + if($this->resolved($abstract)) + $this->rebound($abstract); } } diff --git a/tests/Container/ContainerTest.php b/tests/Container/ContainerTest.php index 88702f83940f..9d12632a7f5c 100755 --- a/tests/Container/ContainerTest.php +++ b/tests/Container/ContainerTest.php @@ -236,6 +236,29 @@ public function testExtendCanBeCalledBeforeBind() $this->assertEquals('foobar', $container->make('foo')); } + public function testExtendReBindingCallback() + { + $_SERVER['_test_rebind'] = false; + + $container = new Container; + $container->rebinding('foo',function (){ + $_SERVER['_test_rebind'] = true; + }); + $container->bind('foo',function (){ + $obj = new StdClass; + + return $obj; + }); + + $container->make('foo'); + + $container->extend('foo', function ($obj, $container) { + return $obj; + }); + + $this->assertTrue($_SERVER['_test_rebind']); + } + public function testResolutionOfDefaultParameters() { $container = new Container; From 0b74d9b986653dd6c28183a52e0d0104d8601a8d Mon Sep 17 00:00:00 2001 From: leoyang90 Date: Sat, 20 May 2017 10:41:32 +0800 Subject: [PATCH 2/4] StyleCI --- src/Illuminate/Container/Container.php | 3 ++- tests/Container/ContainerTest.php | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Container/Container.php b/src/Illuminate/Container/Container.php index 7b0466ba1754..c55c606eca5a 100755 --- a/src/Illuminate/Container/Container.php +++ b/src/Illuminate/Container/Container.php @@ -344,8 +344,9 @@ public function extend($abstract, Closure $closure) } else { $this->extenders[$abstract][] = $closure; - if($this->resolved($abstract)) + if($this->resolved($abstract)) { $this->rebound($abstract); + } } } diff --git a/tests/Container/ContainerTest.php b/tests/Container/ContainerTest.php index 8c8688e4db22..31ad9a8289fe 100755 --- a/tests/Container/ContainerTest.php +++ b/tests/Container/ContainerTest.php @@ -241,7 +241,7 @@ public function testExtendInstanceRebindingCallback() $_SERVER['_test_rebind'] = false; $container = new Container; - $container->rebinding('foo', function (){ + $container->rebinding('foo', function () { $_SERVER['_test_rebind'] = true; }); @@ -260,10 +260,10 @@ public function testExtendBindRebindingCallback() $_SERVER['_test_rebind'] = false; $container = new Container; - $container->rebinding('foo', function (){ + $container->rebinding('foo', function () { $_SERVER['_test_rebind'] = true; }); - $container->bind('foo', function (){ + $container->bind('foo', function () { $obj = new StdClass; return $obj; From c666ba9541a637ccb96e6777e659543f90f62148 Mon Sep 17 00:00:00 2001 From: leoyang90 Date: Sat, 20 May 2017 10:42:47 +0800 Subject: [PATCH 3/4] StyleCI --- src/Illuminate/Container/Container.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Container/Container.php b/src/Illuminate/Container/Container.php index c55c606eca5a..a3a6f1bdae8d 100755 --- a/src/Illuminate/Container/Container.php +++ b/src/Illuminate/Container/Container.php @@ -344,7 +344,7 @@ public function extend($abstract, Closure $closure) } else { $this->extenders[$abstract][] = $closure; - if($this->resolved($abstract)) { + if($this->resolved($abstract)) { $this->rebound($abstract); } } From cf3dc1bb0952c08da5a70625c73c562833956beb Mon Sep 17 00:00:00 2001 From: leoyang90 Date: Sat, 20 May 2017 10:43:48 +0800 Subject: [PATCH 4/4] StyleCI --- src/Illuminate/Container/Container.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Container/Container.php b/src/Illuminate/Container/Container.php index a3a6f1bdae8d..0945cb01ce52 100755 --- a/src/Illuminate/Container/Container.php +++ b/src/Illuminate/Container/Container.php @@ -344,7 +344,7 @@ public function extend($abstract, Closure $closure) } else { $this->extenders[$abstract][] = $closure; - if($this->resolved($abstract)) { + if ($this->resolved($abstract)) { $this->rebound($abstract); } }