sessionKeyPrefix . $id->value; } #[\Override] public function find(BasketId $id): ?Basket { $sessionKey = $this->getSessionKey($id); if ($this->session->has($sessionKey)) { $sessionData = $this->session->get($sessionKey); if (is_string($sessionData)) { try { /** @var array $decoded */ $decoded = json_decode( $sessionData, true, 512, JSON_THROW_ON_ERROR ); if (is_array($decoded)) { return $this->serializer->fromArray($decoded); } } catch (\Throwable $e) { // Ignore and fall back to null } } } return null; } #[\Override] public function persist(Basket $basket): void { $this->session->put( $this->getSessionKey($basket->id), json_encode($this->serializer->toArray($basket), JSON_THROW_ON_ERROR) ); } #[\Override] public function delete(Basket $basket): void { $this->session->forget($this->getSessionKey($basket->id)); } }