*/ class AddTaskToQueue implements Action, ServiceLocatorAwareInterface { use ServiceLocatorAwareTrait; public function __invoke($params): Report { $action = array_shift($params); if (!class_exists($action)) { return Report::createError('Action class does not exist'); } if (!is_subclass_of($action, Action::class)) { return Report::createError('Action in not instance of ' . Action::class); } $actionInstance = new $action(); /** @var QueueDispatcherInterface $queueDispatcher */ $queueDispatcher = $this->getServiceLocator()->get(QueueDispatcherInterface::SERVICE_ID); $queueDispatcher->createTask($actionInstance, $params, $action); return Report::createInfo('Task ' . $action . ' has been successfully added to the queue'); } }