Skip to content

Commit

Permalink
simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Oct 3, 2018
1 parent f10fe3e commit e2476c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
15 changes: 6 additions & 9 deletions src/Illuminate/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

/**
Expand Down
11 changes: 3 additions & 8 deletions src/Illuminate/Container/ContextualBindingBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Container;

use Illuminate\Support\Arr;
use Illuminate\Contracts\Container\ContextualBindingBuilder as ContextualBindingBuilderContract;

class ContextualBindingBuilder implements ContextualBindingBuilderContract
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit e2476c1

Please sign in to comment.