class RemoveHandler { private $entityManager; // To inject public function handle(RemoveCommand $removeCommand): string { $item = $removeCommand->getItem(); $this->entityManager->remove($item); $this->entityManager->flush(); // We can find a better way return $item->getUuid(); // It can return a result! } }
controller: Great, Romaric... but what is the interest? /** * @ParamConverter("item") */ public function apiAction(Item $item) { $command = new RemoveCommand($item); $uuid = $this->get('tactician.commandbus')->handle($command); return new JsonResponse(['uuid' => $uuid]); }