Skip to content

Commit

Permalink
feat: Override _api_operation attribute as well when using `GetWebR…
Browse files Browse the repository at this point in the history
…esponseByPathController`
  • Loading branch information
ambroisemaupate committed Feb 13, 2024
1 parent 1de377b commit 89dd9a3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 89dd9a3

Please sign in to comment.