*/ readonly class DeleteMonitorHandler implements HandlerInterface { public function __construct( private MessageBusInterface $bus, private MonitorRepository $monitorRepository, ) {} public function handle(CommandInterface $command): ResultInterface { $monitor = $this->monitorRepository->find($command->monitorId); $this->monitorRepository->getEntityManager()->remove($monitor); $this->monitorRepository->getEntityManager()->flush(); $this->bus->dispatch(new AddEventLogCommand( $monitor->getUser(), MonitorEvents::MONITOR_DELETED->type(), MonitorEvents::MONITOR_DELETED->message(), (array) $monitor )); return new DeleteMonitorResult( status: 'OK', result: [], monitor: $monitor ); } }