Stack Overflow en español Asked by xvrcjs on November 10, 2021
Estoy realizando una API en un framework llamado Sylius que utiliza el framework symfony como base.
Actualmente no me reconoce la clase del controlador de la API que resuelve la lógica de la API
Tengo un controlador con su respectiva declaración:
<?php
declare(strict_types=1);
namespace EasyCommerceShopApiPluginControllerOrder;
use EasyCommerceShopApiPluginFactoryValidationErrorViewFactoryInterface;
use EasyCommerceShopApiPluginRequestOrderCustomerOrderCancellationRequest;
use FOSRestBundleViewView;
use FOSRestBundleViewViewHandlerInterface;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentMessengerMessageBusInterface;
use SymfonyComponentValidatorValidatorValidatorInterface;
final class CustomerOrderCancellationAction
{
/** @var ViewHandlerInterface */
private $viewHandler;
/** @var MessageBusInterface */
private $bus;
/** @var ValidatorInterface */
private $validator;
/** @var ValidationErrorViewFactoryInterface */
private $validationErrorViewFactory;
public function __construct(
ViewHandlerInterface $viewHandler,
MessageBusInterface $bus,
ValidatorInterface $validator,
ValidationErrorViewFactoryInterface $validationErrorViewFactory
) {
$this->viewHandler = $viewHandler;
$this->bus = $bus;
$this->validator = $validator;
$this->validationErrorViewFactory = $validationErrorViewFactory;
}
public function __invoke(Request $request): Response
{
$pickupRequest = new CustomerOrderCancellationRequest($request);
$validationResults = $this->validator->validate($pickupRequest);
if (0 === count($validationResults)) {
$this->bus->dispatch($pickupRequest->getCommand());
return $this->viewHandler->handle(View::create(null, Response::HTTP_NO_CONTENT));
}
return $this->viewHandler->handle(View::create($this->validationErrorViewFactory->create($validationResults), Response::HTTP_BAD_REQUEST));
}
}
El controlador lo declaro de la siguiente forma:
<service id="sylius.shop_api_plugin.controller.order.customer_order_cancellation_action"
class="EasyCommerceShopApiPluginControllerOrderCustomerOrderCancellationAction"
>
<argument type="service" id="fos_rest.view_handler" />
<argument type="service" id="sylius_shop_api_plugin.command_bus" />
<argument type="service" id="validator" />
<argument type="service" id="sylius.shop_api_plugin.factory.validation_error_view_factory" />
</service>
La ruta la declaro de la siguiente forma:
sylius_shop_api_customer_order_cancellation:
path: /orders/{tokenValue}/cancellation
methods: [PUT]
defaults:
_controller: sylius.shop_api_plugin.controller.order.customer_order_cancellation_action
Y me devuelve el siguiente error:
{
"code": 500,
"message": "Attempted to load class "CustomerOrderCancellationAction" from namespace "EasyCommerce\ShopApiPlugin\Controller\Order".nDid you forget a "use" statement for another namespace?"
}
Para probar si la ruta me quedó bien configurada lo apunté a otro controlador y funciona. El problema es con el controlador que cree.
Como eran dos espacios de nombres diferentes en el proyecto principal tuve que borrar cache:
bin/console cache:clear --env=dev
Y posteriormente recargar el composer:
composer dump-autoload
De esa forma me vuelve a cargar todos los espacios de nombre
Answered by xvrcjs on November 10, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP