diff --git a/src/Illuminate/Container/Container.php b/src/Illuminate/Container/Container.php index 63607ee37284..39bf3bb59726 100755 --- a/src/Illuminate/Container/Container.php +++ b/src/Illuminate/Container/Container.php @@ -7,6 +7,7 @@ use LogicException; use ReflectionClass; use ReflectionParameter; +use Illuminate\Support\Arr; use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Contracts\Container\Container as ContainerContract; @@ -134,22 +135,18 @@ class Container implements ArrayAccess, ContainerContract /** * Define a contextual binding. * - * @param string|array $concrete + * @param array|string $concrete * @return \Illuminate\Contracts\Container\ContextualBindingBuilder */ public function when($concrete) { - if (is_array($concrete)) { - $alias = []; + $aliases = []; - foreach ($concrete as $c) { - $alias[] = $this->getAlias($c); - } - } else { - $alias = $this->getAlias($concrete); + foreach (Arr::wrap($concrete) as $c) { + $aliases[] = $this->getAlias($c); } - return new ContextualBindingBuilder($this, $alias); + return new ContextualBindingBuilder($this, $aliases); } /** diff --git a/src/Illuminate/Container/ContextualBindingBuilder.php b/src/Illuminate/Container/ContextualBindingBuilder.php index bf15920f74f1..2bd4b5ad9d8f 100644 --- a/src/Illuminate/Container/ContextualBindingBuilder.php +++ b/src/Illuminate/Container/ContextualBindingBuilder.php @@ -2,6 +2,7 @@ namespace Illuminate\Container; +use Illuminate\Support\Arr; use Illuminate\Contracts\Container\ContextualBindingBuilder as ContextualBindingBuilderContract; class ContextualBindingBuilder implements ContextualBindingBuilderContract @@ -61,14 +62,8 @@ public function needs($abstract) */ public function give($implementation) { - if (is_array($this->concrete)) { - foreach ($this->concrete as $c) { - $this->container->addContextualBinding($c, $this->needs, $implementation); - } - } else { - $this->container->addContextualBinding( - $this->concrete, $this->needs, $implementation - ); + foreach (Arr::wrap($this->concrete) as $concrete) { + $this->container->addContextualBinding($concrete, $this->needs, $implementation); } } }