From 89dd9a3cf8378749055ba7ddbeeae27cf838899f Mon Sep 17 00:00:00 2001 From: Ambroise Maupate Date: Tue, 13 Feb 2024 17:49:05 +0100 Subject: [PATCH] feat: Override `_api_operation` attribute as well when using `GetWebResponseByPathController` --- .env | 2 +- .../src/Api/Controller/GetWebResponseByPathController.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.env b/.env index 3387bd10..7f775c64 100644 --- a/.env +++ b/.env @@ -36,7 +36,7 @@ PUBLIC_PMA_PORT=8686 PUBLIC_SOLR_PORT=8684 PUBLIC_MAILER_PORT=8625 PUBLIC_DB_PORT=33060 -SMTP_MAILER_PORT=1025 +SMTP_MAILER_PORT=1125 # To use with Traefik and your local dev environment # On linux you can use dnsmasq to redirect all DNS for *.test TLD to your machine. diff --git a/lib/RoadizCoreBundle/src/Api/Controller/GetWebResponseByPathController.php b/lib/RoadizCoreBundle/src/Api/Controller/GetWebResponseByPathController.php index 87523f85..15ac2557 100644 --- a/lib/RoadizCoreBundle/src/Api/Controller/GetWebResponseByPathController.php +++ b/lib/RoadizCoreBundle/src/Api/Controller/GetWebResponseByPathController.php @@ -6,10 +6,8 @@ use ApiPlatform\Api\IriConverterInterface; use ApiPlatform\Exception\InvalidArgumentException; -use ApiPlatform\Exception\OperationNotFoundException; use ApiPlatform\Exception\ResourceClassNotFoundException; use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; -use Psr\Log\LoggerInterface; use RZ\Roadiz\Core\AbstractEntities\PersistableInterface; use RZ\Roadiz\CoreBundle\Api\DataTransformer\WebResponseDataTransformerInterface; use RZ\Roadiz\CoreBundle\Api\Model\WebResponseInterface; @@ -25,6 +23,7 @@ final class GetWebResponseByPathController extends AbstractController { public function __construct( + private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory, private readonly PathResolverInterface $pathResolver, private readonly WebResponseDataTransformerInterface $webResponseDataTransformer, private readonly IriConverterInterface $iriConverter, @@ -54,12 +53,13 @@ public function __invoke(?Request $request): ?WebResponseInterface */ $resourceClass = get_class($resource); $operationName = $this->apiResourceOperationNameGenerator->generateGetByPath($resourceClass); - + $operation = $this->resourceMetadataCollectionFactory->create($resourceClass)->getOperation($operationName); + $request->attributes->set('_api_operation', $operation); $request->attributes->set('_api_operation_name', $operationName); $request->attributes->set('_api_resource_class', $resourceClass); $request->attributes->set('_stateless', true); return $this->webResponseDataTransformer->transform($resource, WebResponseInterface::class); - } catch (ResourceNotFoundException $exception) { + } catch (ResourceNotFoundException|ResourceClassNotFoundException $exception) { throw $this->createNotFoundException($exception->getMessage(), $exception); } }