@param CommandInterface $command
@param bool             $first

@throws Exception
@return AbstractAggregateRoot|null
351736
protected function invokeHandler(CommandInterface $command, $first)
    {
        $aggregateRoot = null;
        try {
            $this->executing = true;

            $commandHandler = $this->locator->getCommandHandlerForCommand($command);

            $aggregateRoot = $commandHandler->handle($command);
        } catch (Exception $exception) {
            $this->executing = false;
            $this->handleException($exception, $first);
        }

        $this->executing = false;

        return $aggregateRoot;
    }
897208
public function commandToRequestTransformer(CommandInterface $command)
    {
        $name = $command->getName();
        if (!isset($this->api[$name])) {
            throw new CommandException('Command not found', $command);
        }
        $action = $this->api[$name];

        $prefix = '';
        if (isset($action['public']) && $command->hasParam('public')) {
            $prefix = '/public';
        }

        $prefixes = [
            'system' => '/systems/{system}',
            'issuer' => '/issuers/{issuer}',
            'program' => '/programs/{program}',
        ];
        if (isset($action['admin_contexts'])) {
            $prefix .= implode('', array_intersect_key($prefixes, array_flip($action['admin_contexts']), array_merge($command->toArray(), $this->adminContext)));
        }
        $path = GuzzleHttp\uri_template($prefix.$action['path'], array_merge($command->toArray(), $this->adminContext));

        $headers = [];
        $body = null;
        if ($command->hasParam('body')) {
            $headers = ['Content-Type' => 'application/json'];
            $body = GuzzleHttp\json_encode($command['body']);
        }

        if ($command->hasParam('query')) {
            $path .= '?'.Psr7\build_query($command['query']);
        }

        return new Psr7\Request($action['method'], $path, $headers, $body);
    }
933426
protected function execute(CommandInterface $command)
    {
        $runner = $this->getCommandRunner();

        $this->lastReturnValue = $runner->run($command);

        $this->checkReturnValue($runner);
    }
228348
protected function prepareRequest(
        CommandInterface $command,
        RequestInterface $request
    ) {
        $visitedLocations = [];
        $operation = $this->description->getOperation($command->getName());

        // Visit each actual parameter
        foreach ($operation->getParams() as $name => $param) {
            /* @var Parameter $param */
            $location = $param->getLocation();
            // Skip parameters that have not been set or are URI location
            if ($location == 'uri' || !$command->hasParam($name)) {
                continue;
            }
            if (!isset($this->locations[$location])) {
                throw new \RuntimeException("No location registered for $name");
            }
            $visitedLocations[$location] = true;
            $request = $this->locations[$location]->visit($command, $request, $param);
        }

        // Ensure that the after() method is invoked for additionalParameters
        /** @var Parameter $additional */
        if ($additional = $operation->getAdditionalParameters()) {
            $visitedLocations[$additional->getLocation()] = true;
        }

        // Call the after() method for each visited location
        foreach (array_keys($visitedLocations) as $location) {
            $request = $this->locations[$location]->after($command, $request, $operation);
        }

        return $request;
    }
60331
public function handle(CommandInterface $command)
    {
        if (!$this->supports(get_class($command))) {
            throw new InvalidArgumentException(
                sprintf(
                    'The command must be an instance of "%s". "%s" given.',
                    $this->getSupportedCommandClassName(),
                    get_class($command)
                )
            );
        }

        return $this->execute($command);
    }
55740
protected function getKeyFromZsetAggregationCommands(string $command, array $arguments)
    {
        $keys = \array_merge([$arguments[0]], \array_slice($arguments, 2, $arguments[1]));

        if ($this->checkSameSlotForKeys($keys)) {
            return $arguments[0];
        }

        return null;
    }
1086162
public function execute(Command $command)
    {
        if ($this->locked === true) {
            $this->queue[] = $command;
            return null;
        }

        $this->locked = true;

        $response = $this->executeIgnoringLock($command);

        $this->executeQueue();

        $this->locked = false;

        return $response;
    }
1055162
final public function handle(CommandInterface $command)
    {
        $this->validateCommand($command);

        try {
            // @todo - Update this to return the succes event object, rather than using the getSuccessEvent() method
            $this->_handle($command);
        } catch (\Exception $exception) {

            // Log exception
            $commandClass = get_class($command);
            $this->logError(
                "Exception throw while handling {$commandClass} command... {$exception->getMessage()}\n",
                $exception
            );

            // Fire failure event
            $this->emit($this->getFailureEvent($exception));

            throw $exception;
        }

        $event = $this->getSuccessEvent($command);
        $this->emit($event);
    }
291895
public function execute(CommandInterface $command, CommandChainInterface $chain)
    {
        return parent::invokeCallbacks($command, $this->getMixer());
    }
13561
public function request(CommandInterface $command)
    {
        if ($command instanceof MultipartDocumentUpload) {
            return $command->execute($this->uploadClient);
        }

        return $command->execute($this->apiClient);
    }
551327
public function run(CommandInterface $command)
    {
        $result = null;

        /** @var RunnerInterface $runner */
        foreach($this->runners as $runner) {
            $result = $runner->run($command, $result);
        }

        return $result;
    }
314672
public function dispatch($command)
    {
        if ($this->decoratee instanceof AuthorizedCommandBusInterface &&
            $command instanceof AuthorizableCommandInterface) {
            if (!$this->decoratee->isAuthorized($command)) {
                throw new CommandAuthorizationException(
                    $this->decoratee->getUserIdentification()->getId(),
                    $command
                );
            }
        }

        $args = array();
        $args['command'] = base64_encode(serialize($command));
        $args['context'] = base64_encode(serialize($this->context));
        $id = \Resque::enqueue($this->queueName, QueueJob::class, $args, true);

        return $id;
    }
757465
protected function validateCommand(CommandInterface $command)
    {
        $this->checkCommandType($command);

        if (!$this->validator instanceof ValidatorInterface) {
            $validatorUnavailableException = new \RuntimeException('Validator is not available');
            $this->logError('Validator service unavailable', $validatorUnavailableException);
            throw $validatorUnavailableException;
        }

        $violationsList = $this->validator->validate($command);

        if (count($violationsList) > 0) {
            throw new InvalidCommandParametersException($violationsList);
        }
    }
773886
final public function execute($command, AnCommandContext $context)
    {
        $identifier = $context->caller->getIdentifier();

        if ($context->entity instanceof AnDomainEntityAbstract) {
            $identifier = $context->entity->getIdentifier();
        }

        $type = $identifier->path;
        $type = array_pop($type);

        $parts = explode('.', $command);
        $method = '_'.($parts[0]).ucfirst($type).ucfirst($parts[1]);

        $result = null;

        if (method_exists($this, $method)) {
            $result = $this->$method($context);
        }

        if ($context->entity) {
            $result = $context->entity->execute($command, $context);
        }

        return $result;
    }
1236718
protected function handle(CommandInterface $command)
	{
		if($command instanceof SelfHandlingCommandInterface)
		{
			return $command->handle();
		}

		$handler = $this->resolveCommandHandler($command);

		return $this->executeCommandHandler($handler, $command);
	}
776095
public function runCommand(Command $command, InputInterface $input, OutputInterface $output) {
    return $this->doRunCommand($command, $input, $output);
  }
925773
public function orderBy($order, $append = true, $first = false)
    {
        return $this->command->orderBy($order, $append, $first);
    }