diff --git a/src/Illuminate/Container/BoundMethod.php b/src/Illuminate/Container/BoundMethod.php index 980d2806ea59..e37fd887bbe6 100644 --- a/src/Illuminate/Container/BoundMethod.php +++ b/src/Illuminate/Container/BoundMethod.php @@ -75,7 +75,7 @@ protected static function callClass($container, $target, array $parameters = [], protected static function callBoundMethod($container, $callback, $default) { if (! is_array($callback)) { - return value($default); + return Util::unwrapIfClosure($default); } // Here we need to turn the array callable into a Class@method string we can use to @@ -87,7 +87,7 @@ protected static function callBoundMethod($container, $callback, $default) return $container->callMethodBinding($method, $callback[0]); } - return value($default); + return Util::unwrapIfClosure($default); } /** diff --git a/src/Illuminate/Container/Container.php b/src/Illuminate/Container/Container.php index 343ebaf7e65b..b74b8b17f6c5 100755 --- a/src/Illuminate/Container/Container.php +++ b/src/Illuminate/Container/Container.php @@ -7,7 +7,6 @@ use Exception; use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Contracts\Container\Container as ContainerContract; -use Illuminate\Support\Arr; use LogicException; use ReflectionClass; use ReflectionException; @@ -144,7 +143,7 @@ public function when($concrete) { $aliases = []; - foreach (Arr::wrap($concrete) as $c) { + foreach (Util::arrayWrap($concrete) as $c) { $aliases[] = $this->getAlias($c); } diff --git a/src/Illuminate/Container/ContextualBindingBuilder.php b/src/Illuminate/Container/ContextualBindingBuilder.php index 78cee82d1827..a52db5d5047c 100644 --- a/src/Illuminate/Container/ContextualBindingBuilder.php +++ b/src/Illuminate/Container/ContextualBindingBuilder.php @@ -4,7 +4,6 @@ use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Container\ContextualBindingBuilder as ContextualBindingBuilderContract; -use Illuminate\Support\Arr; class ContextualBindingBuilder implements ContextualBindingBuilderContract { @@ -63,7 +62,7 @@ public function needs($abstract) */ public function give($implementation) { - foreach (Arr::wrap($this->concrete) as $concrete) { + foreach (Util::arrayWrap($this->concrete) as $concrete) { $this->container->addContextualBinding($concrete, $this->needs, $implementation); } } diff --git a/src/Illuminate/Container/Util.php b/src/Illuminate/Container/Util.php new file mode 100644 index 000000000000..d96a003bc07d --- /dev/null +++ b/src/Illuminate/Container/Util.php @@ -0,0 +1,36 @@ +assertSame('foo', Util::unwrapIfClosure('foo')); + $this->assertSame('foo', UtiL::unwrapIfClosure(function () { + return 'foo'; + })); + } + + public function testArrayWrap() + { + $string = 'a'; + $array = ['a']; + $object = new \stdClass; + $object->value = 'a'; + $this->assertEquals(['a'], Util::arrayWrap($string)); + $this->assertEquals($array, Util::arrayWrap($array)); + $this->assertEquals([$object], Util::arrayWrap($object)); + $this->assertEquals([], Util::arrayWrap(null)); + $this->assertEquals([null], Util::arrayWrap([null])); + $this->assertEquals([null, null], Util::arrayWrap([null, null])); + $this->assertEquals([''], Util::arrayWrap('')); + $this->assertEquals([''], Util::arrayWrap([''])); + $this->assertEquals([false], Util::arrayWrap(false)); + $this->assertEquals([false], Util::arrayWrap([false])); + $this->assertEquals([0], Util::arrayWrap(0)); + + $obj = new \stdClass; + $obj->value = 'a'; + $obj = unserialize(serialize($obj)); + $this->assertEquals([$obj], Util::arrayWrap($obj)); + $this->assertSame($obj, Util::arrayWrap($obj)[0]); + } +}