From 3953f6f0a37e38fd8a3d6b0d9faa80f59e00ec01 Mon Sep 17 00:00:00 2001 From: Antoine Bluchet Date: Fri, 8 Sep 2023 16:05:29 +0200 Subject: [PATCH] fix(state): read provider without request (#5803) --- src/State/Provider/ReadProvider.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/State/Provider/ReadProvider.php b/src/State/Provider/ReadProvider.php index bf33c875d14..8a981324a59 100644 --- a/src/State/Provider/ReadProvider.php +++ b/src/State/Provider/ReadProvider.php @@ -53,7 +53,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c return null; } - if (null === $filters = $request->attributes->get('_api_filters')) { + if (null === $filters = $request?->attributes->get('_api_filters')) { $queryString = RequestParser::getQueryString($request); $filters = $queryString ? RequestParser::parseRequestParams($queryString) : null; } @@ -62,7 +62,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c $context['filters'] = $filters; } - if ($this->serializerContextBuilder) { + if ($this->serializerContextBuilder && $request) { // Builtin data providers are able to use the serialization context to automatically add join clauses $context += $this->serializerContextBuilder->createFromRequest($request, true, [ 'resource_class' => $operation->getClass(), @@ -87,8 +87,8 @@ public function provide(Operation $operation, array $uriVariables = [], array $c throw new NotFoundHttpException('Not Found'); } - $request->attributes->set('data', $data); - $request->attributes->set('previous_data', $this->clone($data)); + $request?->attributes->set('data', $data); + $request?->attributes->set('previous_data', $this->clone($data)); return $data; }