Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Fix loading deferred providers for binding interfaces and implementations #31629

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Create resolve method which loads deferred providers if needed
It allows resolving object by interface when using separate deferred providers for interface and implementation.
  • Loading branch information
lprzybylek committed Feb 27, 2020
commit 746f2e9840900474172665fa4d73c7654d379b1d
31 changes: 30 additions & 1 deletion src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,11 +769,40 @@ public function make($abstract, array $parameters = [])
{
$abstract = $this->getAlias($abstract);

$this->loadDeferredProviderIfNeeded($abstract);

return parent::make($abstract, $parameters);
}

/**
* Load deferred provider if $abstract is deferred and instance was not loaded
*
* @param string $abstract
*/
private function loadDeferredProviderIfNeeded($abstract)
{
if ($this->isDeferredService($abstract) && ! isset($this->instances[$abstract])) {
$this->loadDeferredProvider($abstract);
}
}

return parent::make($abstract, $parameters);
/**
* Resolve the given type from the container.
*
* (Overriding Container::resolve)
*
* @param string $abstract
* @param array $parameters
* @param bool $raiseEvents
* @return mixed
*/
protected function resolve($abstract, $parameters = [], $raiseEvents = true)
{
$abstract = $this->getAlias($abstract);

$this->loadDeferredProviderIfNeeded($abstract);

return parent::resolve($abstract, $parameters, $raiseEvents);
}

/**
Expand Down