diff --git a/src/Knp/Menu/Matcher/Matcher.php b/src/Knp/Menu/Matcher/Matcher.php index 9b631eb7..5cd69720 100644 --- a/src/Knp/Menu/Matcher/Matcher.php +++ b/src/Knp/Menu/Matcher/Matcher.php @@ -11,9 +11,9 @@ class Matcher implements MatcherInterface { /** - * @var \SplObjectStorage + * @var \WeakMap */ - private \SplObjectStorage $cache; + private \WeakMap $cache; /** * @var iterable|VoterInterface[] @@ -26,7 +26,7 @@ class Matcher implements MatcherInterface public function __construct($voters = []) { $this->voters = $voters; - $this->cache = new \SplObjectStorage(); + $this->cache = new \WeakMap(); } public function isCurrent(ItemInterface $item): bool @@ -36,7 +36,7 @@ public function isCurrent(ItemInterface $item): bool return $current; } - if ($this->cache->contains($item)) { + if ($this->cache->offsetExists($item)) { return $this->cache[$item]; } @@ -71,6 +71,6 @@ public function isAncestor(ItemInterface $item, ?int $depth = null): bool public function clear(): void { - $this->cache = new \SplObjectStorage(); + $this->cache = new \WeakMap(); } }