public function execute($action, array $payload)
    {
        $executor = $this->getExecutor($action);

        // dispatch pre event, listeners may change the payload here
        $event = new ExecutionEvent($executor, $action, $payload);
        $this->dispatcher->dispatch(WorkerEvents::PRE_EXECUTE_ACTION, $event);

        try {
            $resolver = $this->getPayloadResolver($executor);
            $payload  = $resolver->resolve($event->getPayload());
        } catch (ExceptionInterface $exception) {
            $this->logger->error(
                sprintf(
                    'Payload %s for "%s" is invalid: %s',
                    json_encode($payload, JSON_UNESCAPED_SLASHES),
                    $action,
                    $exception->getMessage()
                )
            );

            return false;
        }

        $result = $executor->execute($payload);
        // dispatch post event, listeners may change the result here
        $event->setResult($result);
        $this->dispatcher->dispatch(WorkerEvents::POST_EXECUTE_ACTION, $event);

        return $event->getResult();
    }
public function execute($action, array $payload)
    {
        $executor = $this->getExecutor($action);

        // dispatch pre event, listeners may change the payload here
        $event = new ExecutionEvent($executor, $action, $payload);
        $this->dispatcher->dispatch(WorkerEvents::PRE_EXECUTE_ACTION, $event);

        try {
            $resolver = $this->getPayloadResolver($executor);
            $payload  = $resolver->resolve($event->getPayload());
        } catch (ExceptionInterface $exception) {
            $this->logger->error(
                sprintf(
                    'Payload %s for "%s" is invalid: %s',
                    json_encode($payload, JSON_UNESCAPED_SLASHES),
                    $action,
                    $exception->getMessage()
                )
            );

            return false;
        }

        $result = $executor->execute($payload);
        // dispatch post event, listeners may change the result here
        $event->setResult($result);
        $this->dispatcher->dispatch(WorkerEvents::POST_EXECUTE_ACTION, $event);

        return $event->getResult();
    }
public function execute ( $ action , array $ payload ) { $ executor = $ this -> getExecutor ( $ action ) ; // dispatch pre event, listeners may change the payload here $ event = new ExecutionEvent ( $ executor , $ action , $ payload ) ; $ this -> dispatcher -> dispatch ( WorkerEvents :: PRE_EXECUTE_ACTION , $ event ) ; try { $ resolver = $ this -> getPayloadResolver ( $ executor ) ; $ payload = $ resolver -> resolve ( $ event -> getPayload ( ) ) ; } catch ( ExceptionInterface $ exception ) { $ this -> logger -> error ( sprintf ( 'Payload %s for "%s" is invalid: %s' , json_encode ( $ payload , JSON_UNESCAPED_SLASHES ) , $ action , $ exception -> getMessage ( ) ) ) ; return false ; } $ result = $ executor -> execute ( $ payload ) ; // dispatch post event, listeners may change the result here $ event -> setResult ( $ result ) ; $ this -> dispatcher -> dispatch ( WorkerEvents :: POST_EXECUTE_ACTION , $ event ) ; return $ event -> getResult ( ) ; }
Executes an action with a specific payload.

@param string $action
@param array  $payload

@return mixed
Executes an action with a specific payload .