*/ final readonly class DeleteClassProcessor implements ProcessorInterface { public function __construct( private ArchiveClassHandler $handler, private ClassRepository $classRepository, private MessageBusInterface $eventBus, private AuthorizationCheckerInterface $authorizationChecker, ) { } /** * @param ClassResource $data */ #[Override] public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): null { $classId = $uriVariables['id'] ?? null; if (!is_string($classId)) { throw new BadRequestHttpException('ID de classe manquant.'); } // Vérifier les permissions avant toute action $class = $this->classRepository->findById(ClassId::fromString($classId)); if ($class === null) { throw new NotFoundHttpException('Classe introuvable.'); } if (!$this->authorizationChecker->isGranted(ClassVoter::DELETE, $class)) { throw new AccessDeniedHttpException('Vous n\'êtes pas autorisé à supprimer cette classe.'); } try { $command = new ArchiveClassCommand(classId: $classId); $archivedClass = ($this->handler)($command); // Dispatch domain events from the archived aggregate foreach ($archivedClass->pullDomainEvents() as $event) { $this->eventBus->dispatch($event); } return null; } catch (ClasseNotFoundException) { throw new NotFoundHttpException('Classe introuvable.'); } catch (ClasseNonSupprimableException $e) { throw new BadRequestHttpException($e->getMessage()); } } }