From 20a856e97ee88bd2327228d07cb917a12c7a4a7b Mon Sep 17 00:00:00 2001 From: Kamil Kokot Date: Mon, 25 May 2020 11:06:28 +0200 Subject: [PATCH] Keep FIFO order for prioritized registry --- src/PrioritizedServiceRegistry.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/PrioritizedServiceRegistry.php b/src/PrioritizedServiceRegistry.php index 5619feb..d2da900 100644 --- a/src/PrioritizedServiceRegistry.php +++ b/src/PrioritizedServiceRegistry.php @@ -22,13 +22,6 @@ final class PrioritizedServiceRegistry implements PrioritizedServiceRegistryInte */ private $registry = []; - /** - * @psalm-var array - * - * @var array - */ - private $sortedRegistry = []; - /** @var bool */ private $sorted = true; @@ -55,15 +48,19 @@ public function __construct(string $interface, string $context = 'service') public function all(): iterable { if ($this->sorted === false) { - $this->sortedRegistry = array_reverse($this->registry); - /** @psalm-suppress InvalidPassByReference Doing PHP magic, it works this way */ - array_multisort(array_column($this->sortedRegistry, 'priority'), \SORT_DESC, $this->sortedRegistry); + array_multisort( + array_column($this->registry, 'priority'), + \SORT_DESC, + array_keys($this->registry), + \SORT_ASC, + $this->registry + ); $this->sorted = true; } - foreach ($this->sortedRegistry as $record) { + foreach ($this->registry as $record) { yield $record['service']; } }