Skip to content

Commit

Permalink
[7.x] Optimize container (#32194)
Browse files Browse the repository at this point in the history
* optimize container

* Update Container.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
nguyenyou and taylorotwell committed Apr 2, 2020
1 parent 194953f commit ed9228d
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/Illuminate/Container/Container.php
Expand Up @@ -662,10 +662,10 @@ public function get($id)
protected function resolve($abstract, $parameters = [], $raiseEvents = true)
{
$abstract = $this->getAlias($abstract);

$concrete = $this->getContextualConcrete($abstract);

$needsContextualBuild = ! empty($parameters) || ! is_null(
$this->getContextualConcrete($abstract)
);
$needsContextualBuild = ! empty($parameters) || ! is_null($concrete);

// If an instance of the type is currently being managed as a singleton we'll
// just return an existing instance instead of instantiating new instances
Expand All @@ -676,7 +676,9 @@ protected function resolve($abstract, $parameters = [], $raiseEvents = true)

$this->with[] = $parameters;

$concrete = $this->getConcrete($abstract);
if (is_null($concrete)) {
$concrete = $this->getConcrete($abstract);
}

// We're ready to instantiate an instance of the concrete type registered for
// the binding. This will instantiate the types, as well as resolve any of
Expand Down Expand Up @@ -723,10 +725,6 @@ protected function resolve($abstract, $parameters = [], $raiseEvents = true)
*/
protected function getConcrete($abstract)
{
if (! is_null($concrete = $this->getContextualConcrete($abstract))) {
return $concrete;
}

// If we don't have a registered resolver or concrete for the type, we'll just
// assume each type is a concrete name and will attempt to resolve it as is
// since the container should be able to resolve concretes automatically.
Expand Down

0 comments on commit ed9228d

Please sign in to comment.