Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Toflar committed Jun 11, 2021
1 parent a5c9589 commit 1cb74c7
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions core-bundle/src/Routing/ResponseContext/ResponseContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ final class ResponseContext
*/
private $services = [];

/**
* @var array
*/
private $current = [];

/**
* @var PartialResponseHeaderBag|null
*/
Expand All @@ -44,7 +49,7 @@ public function addLazy(string $classname, \Closure $factory)

public function has(string $serviceId): bool
{
return isset($this->services[$serviceId]);
return isset($this->current[$serviceId]);
}

/**
Expand All @@ -62,10 +67,12 @@ public function get(string $serviceId)
throw new \InvalidArgumentException(sprintf('Service "%s" does not exist.', $serviceId));
}

$serviceId = $this->current[$serviceId];

// Lazy load the ones with factories
if ($this->services[$serviceId] instanceof \Closure) {
$service = $this->services[$serviceId]();
$this->registerService($serviceId, $service);
$this->services[$serviceId] = $service;
}

return $this->services[$serviceId];
Expand All @@ -86,9 +93,11 @@ public function getHeaderBag(): PartialResponseHeaderBag
private function registerService(string $serviceId, $objectOrFactory): void
{
$this->services[$serviceId] = $objectOrFactory;
$this->current[$serviceId] = $serviceId;

foreach ($this->getAliases($serviceId) as $alias) {
$this->services[$alias] = $objectOrFactory;
$this->current[$alias] = $serviceId;
}
}

Expand Down

0 comments on commit 1cb74c7

Please sign in to comment.