From a39c50e74211255789e33e01a81e872d0f1a4a34 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Wed, 2 Oct 2024 16:35:25 +0200 Subject: [PATCH] BUGFIX: Simplify `projectionState` to be more reliable Previously if called with `ProjectionStateInterface::class` it would return the first state which will then not be callable again by its fqn. Now only fqn are allowed. Initially the interface logic was needed for interchangeable cr readmodel projection states --- .../Classes/ContentRepository.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Neos.ContentRepository.Core/Classes/ContentRepository.php b/Neos.ContentRepository.Core/Classes/ContentRepository.php index 5fe1aad62a8..0006fdb9310 100644 --- a/Neos.ContentRepository.Core/Classes/ContentRepository.php +++ b/Neos.ContentRepository.Core/Classes/ContentRepository.php @@ -162,18 +162,17 @@ public function handle(CommandInterface $command): CommandResult */ public function projectionState(string $projectionStateClassName): ProjectionStateInterface { + if (!isset($this->projectionStateCache)) { + foreach ($this->projectionsAndCatchUpHooks->additionalProjections as $projection) { + $projectionState = $projection->getState(); + $this->projectionStateCache[$projectionState::class] = $projectionState; + } + } if (isset($this->projectionStateCache[$projectionStateClassName])) { /** @var T $projectionState */ $projectionState = $this->projectionStateCache[$projectionStateClassName]; return $projectionState; } - foreach ($this->projectionsAndCatchUpHooks->additionalProjections as $projection) { - $projectionState = $projection->getState(); - if ($projectionState instanceof $projectionStateClassName) { - $this->projectionStateCache[$projectionStateClassName] = $projectionState; - return $projectionState; - } - } throw new \InvalidArgumentException(sprintf('A projection state of type "%s" is not registered in this content repository instance.', $projectionStateClassName), 1662033650); }