Skip to content

Commit

Permalink
Added parameters argument to resolveLiteral
Browse files Browse the repository at this point in the history
  • Loading branch information
tlmcclatchey authored Aug 4, 2024
1 parent a620ed6 commit da838a0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/ServiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private function resolve(string $className, bool $instantiate, array $parameters
// First step is to check if the service has already been registered, and return it,
// as that will take precedence over the rest.
if (array_key_exists($className, $this->services)) {
return $this->resolveLiteral($className, $instantiate);
return $this->resolveLiteral($className, $instantiate, $parameters);
}

// Next is to check if a service provider exists for this specific class
Expand All @@ -246,7 +246,7 @@ private function resolve(string $className, bool $instantiate, array $parameters
}

// Try to resolve the literal service again
return $this->resolveLiteral($realClassName, $instantiate);
return $this->resolveLiteral($realClassName, $instantiate, $parameters);
}

/**
Expand All @@ -258,15 +258,16 @@ private function resolve(string $className, bool $instantiate, array $parameters
* @return bool|object False if the service cannot be resolved, the instantiated service if it exists, or true if the service exists but $instantiate is false.
* @throws ServiceResolutionException
*/
private function resolveLiteral(string $className, bool $instantiate): bool|object
private function resolveLiteral(string $className, bool $instantiate, array $parameters = []): bool|object
{
// If the service exists, return true or instantiate (if needed) and return
// the object depending on the $instantiate state
if (array_key_exists($className, $this->services)) {
if (!$instantiate) return true;
if (!is_object($this->services[$className])) {
try {
$this->services[$className] = $this->di->instantiate($className, $this->services[$className]);

$this->services[$className] = $this->di->instantiate($className, array_merge($this->services[$className], $parameters));
if ($this->services[$className] instanceof BootstrapperContract)
{
$this->services[$className]->bootstrap($this);
Expand Down

0 comments on commit da838a0

Please sign in to comment.