Skip to content

Commit

Permalink
extend can modify exists windwalker-io/core#1170
Browse files Browse the repository at this point in the history
  • Loading branch information
asika32764 committed Nov 6, 2023
1 parent d549af5 commit 667f123
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/di/src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ public function has(string $id): bool
return $this->getDefinition($id) !== null;
}

public function hasCached(string $id): bool
{
return $this->getDefinition($id)?->getCache() !== null;
}

/**
* Remove an item from container.
*
Expand Down Expand Up @@ -607,6 +612,10 @@ public function extend(string $id, Closure $closure): static
$this->extends[$id] ??= [];
$this->extends[$id][] = $closure;

if ($this->hasCached($id)) {
$this->modify($id, $closure);
}

return $this;
}

Expand Down

0 comments on commit 667f123

Please sign in to comment.