Execute the handler

@param KCommandInterface         $command    The command
@param KCommandChainInterface    $chain      The chain executing the command
@return mixed|null If a handler breaks, returns the break condition. NULL otherwise.
337980
public function execute(KCommandInterface $command, KCommandChainInterface $chain)
    {
        $parts  = explode('.', $command->getName());
        $method = '_'.$parts[0].ucfirst($parts[1]);

        if(method_exists($this, $method)) {
            return $this->$method($command);
        }
    }
1113628
public function execute($command = null, array $args = array(), array $options = array())
    {
        $command = $command ?: $this->defaultCommand;
        if (!isset($this->commands[$command])) {
            throw new ConsoleException("Command '$command' does not exist");
        }
        
        $callback = $this->commands[$command];
        if (is_callable($callback)) {
            $params = array($args, $options);
            if (is_string($callback)) {
                if (strpos($callback, '::') !== false) {
                    list($classname, $methodname) = explode('::', $callback);
                    $reflection = new ReflectionMethod($classname, $methodname);
                } else {
                    $reflection = new ReflectionFunction($callback);
                }
                $params = Utils::computeFuncParams($reflection, $args, $options);
            }
            $params[] = $this;
            return call_user_func_array($callback, $params);
        }

        $method = new ReflectionMethod($callback, 'execute');
        $params = Utils::computeFuncParams($method, $args, $options);
        return $method->invokeArgs(new $callback($this), $params);
    }
375206
public function dispatch(Command $command, CommandCallback $callback = null)
    {
        $command = $this->intercept($command);

        $handler = $this->handlerRegistry->findCommandHandlerFor($command);

        $this->unitOfWork->start();
        $interceptorChain = new DefaultInterceptorChain($command, $this->unitOfWork, $handler, ...$this->handlerInterceptors);

        try {
            $result = $interceptorChain->proceed();
            if (null !== $callback) {
                $callback->onSuccess($result);
            }
        } catch (\Exception $exception) {
            $this->unitOfWork->rollback($exception);
            if (null !== $callback) {
                $callback->onFailure($exception);
            }

            throw $exception;
        }

        $this->unitOfWork->commit();

        return $result;
    }
869469
public function resolve(interfaces\commands\Command $command): interfaces\handlers\Handler
    {
        $commandClass = get_class($command);

        if (isset($this->handlers[$commandClass])) {
            $handler = $this->handlers[$commandClass];

            return is_object($handler) ? $handler : $this->createHandler($handler);
        }

        if ($command instanceof interfaces\commands\PlainCommand) {
            return $this->createHandler($this->plainCommandHandlerClassName);
        }

        $handlerClass = $commandClass . 'Handler';
        if (class_exists($handlerClass)) {
            return $this->createHandler($handlerClass);
        }

        $handlerClass = str_replace('\\commands\\', '\\handlers\\', $handlerClass);
        if (class_exists($handlerClass)) {
            return $this->createHandler($handlerClass);
        }

        throw new Exception("Could not terminate the handler of a command of type \"{$commandClass}\"");
    }
607207
public function execute($command, callable $next)
    {
        $handledCommand = $next($command);

        if ($handledCommand instanceof CommandError) {
            $data = ['_error' => $handledCommand->getException()->getMessage()];
        } elseif (is_array($handledCommand)) {
            $data = array_map(function ($item) {
                return $this->extractor->extract($item);
            }, $handledCommand);
        } else {
            $data = $this->extractor->extract($handledCommand);
        }

        return $this->createResponseFor($data);
    }
1077481
public function findHandler(Command $command)
    {
        $command_name = get_class($command);

        return isset($this->handlers[$command_name]) ? $this->handlers[$command_name] : null;
    }
1075591
public function execute(Command $command)
    {
        $handler = $this->resolver->resolve($command);

        return $handler->handle($command);
    }
859489
public function dispatch(CommandInterface $command, $callback = null){

	    if (!$command->getIdentity() && $this->getDefaultIdentity()) {
            $command->setIdentity($this->getDefaultIdentity());
	    }

	    $service     = $command->getService();
	    $operation   = $command->getOperation();
	    $context     = $command->getContext();
	    $argv        = $command->getParams();
	    $exception = null;

	    if(!$this->exists($command->getService())){
	        throw new ServiceNotFoundException(sprintf(
                'Service "%s" not found', $command->getService()));
	    }

	    $responses = null;

        // Notify, that a (background) job is about to start
        if ($command->getJob()) {
            $jobEvent = $this->createEvent(
                'job.start', $command);

            $this->getEventManager()
                ->trigger($jobEvent);
        }

		// Prepare and trigger init.<service>.<operation> event
		$initEvent = strtolower('init.'.$service.'.'.$operation);

		if(!$this->getEventManager()->getListeners($initEvent)->isEmpty()){
		    $e = $this->createEvent($initEvent, $command);

		    $eventResponses = $this->trigger(
	            $e,
	            function($response){if($response === false) return true;}
		    );

		    if($eventResponses->stopped() && $eventResponses->last() === false){
		        $responses = new ResponseCollection();
		        $responses->setStopped(true);
		    }
		}

		// Dispatch command
		if ($responses === null) {
		    try{
		        $responses = $this->getLoader()->getCommandManager()->trigger(
                    $command,
                    $callback
	            );
		    } catch(\Exception $ex) {
		        $exception = $ex;
		    }
		}

		// Prepare and trigger final.<service>.<operation> event
		$finalEvent = strtolower('final.'.$service.'.'.$operation);

		if(!$this->getEventManager()->getListeners($finalEvent)->isEmpty()){

		    $e = $this->createEvent($finalEvent, $command);

		    // Set exception
		    if ($exception) {
		        $e->setException($exception);
		    }

		    $this->trigger($e);

		    // Listeners have a chance to clear (or change) the exception
		    $exception = $e->getException();
		}

        // Notify that the job has ended
        if ($command->getJob()) {
            $jobEvent = $this->createEvent('job.end', $command);

            if ($exception) {
                $jobEvent->setException($exception);
            }
            $this->trigger($jobEvent);
        }

		// Throw exception if it still exists
		if ($exception instanceof \Exception) {
		    throw $exception;
		}

		return $responses;
	}
1017791
def execute(event)
      old_chain = @chain
      @bot.debug 'Executing bare chain'
      result = execute_bare(event)

      @chain_args ||= []

      @bot.debug "Found chain args #{@chain_args}, preliminary result #{result}"

      @chain_args.each do |arg|
        case arg.first
        when 'repeat'
          new_result = ''
          executed_chain = divide_chain(old_chain).last

          arg[1].to_i.times do
            chain_result = CommandChain.new(executed_chain, @bot).execute(event)
            new_result += chain_result if chain_result
          end

          result = new_result
          # TODO: more chain arguments
        end
      end

      result
    end
1351478
public function handle($command)
    {
        $this->commandStack[] = $command;

        if ($this->executing) {
            return;
        }

        $first = true;

        while ($command = array_shift($this->commandStack)) {
            $this->invokeHandler($command, $first);
            $first = false;
        }
    }
129371
protected function execute($command)
    {
        $status = null;
        $result = array();
        exec($command, $result, $status);
        return !$status ? $result : null;
    }
339054
public function command($command, $method) {

        self::$commands[] = $command;
        self::$callbacks[$command] = $method;
    }
782173
public function run(string $command, Closure $callback = null): Process
    {
        set_time_limit(0);
        gc_disable();

        $process = new Process($this->buildCommand($command));
        $process->setWorkingDirectory(base_path());
        $process->setTimeout(null);

        try {
            $process->mustRun(function($type, $buffer) use($callback, $process) {
                if (empty($buffer)) {
                    return null;
                }

                if ($callback instanceof Closure) {
                    $callback($process, $type, $buffer);
                }
            });
        } catch (Exception $e) {
            Log::error($e);
            throw $e;
        }

        return $process;
    }
1311479
public void execRun(String command) throws IOException, PHPException {
	    writeCommand("R" + command);
	    phpConsoleLogger.write(command);
		String readLine = readLine();
        phpConsoleLogger.read(readLine);
		
	}
263931
public function handle(CommandInterface $command)
    {
        $object = $command->getParameter('data');

        if ($command->hasParameter('class')) {
            $class = $command->getParameter('class');
            if (!($object instanceof $class)) {
                return CommandResult::error('invalid_instance');
            }
        }

        try {
            $this->objectManager->flush();
        } catch (ForeignKeyConstraintViolationException $e) {
            return CommandResult::error('constraint_violation');
        }
    }
841212
public function invoke(IDefinition $definition, $command) {
        $handler = $definition->getHandler();

        if ($this->isValidHandlerClass($handler)) {
            $handler = $this->createHandler($handler);
        }

        if ($this->isValidHandler($handler)) {
            return $this->invokeHandler($handler, $command);
        }

        throw new InvalidCommandHandlerException(s(
            'Handler "%s" must implement method "handle($command)".',
            is_string($handler) ? $handler : get_type($handler)
        ));
    }
884313
public function dispatch(CommandInterface $command, bool $qeueEvents = false): void
    {
        try {
            if ($command instanceof CommandInterface) {
                // Reset aggregates.
                $this->aggregates = [];

                /**
                 * Get Handler for Command.
                 *
                 * @var HandlerInterface $handler
                 */
                $handlerClass = $command->getHandlerClass();
                $handler = new $handlerClass($this->messageBus, $this->aggregateFactory);

                if ($handler instanceof HandlerInterface) {
                    // Invoke Handler.
                    $handler($command, $this->aggregates);

                    // Check for events on aggregates, pass them to EventBus#publish()
                    $events = [];

                    /** @var AggregateInterface $aggregate */
                    foreach ($this->aggregates as $aggregate) {
                        /** @var array $pendingEvents */
                        $pendingEvents = $aggregate->getPendingEvents();

                        $events += $pendingEvents;
                    }

                    $this->eventBus->publish($events, $this, $qeueEvents);
                } else {
                    throw new InterfaceException(\get_class($handler).' must implement '.HandlerInterface::class);
                }
            } else {
                throw new InterfaceException(\get_class($command).' must implement '.CommandInterface::class);
            }
        } catch (InterfaceException $e) {
            $this->messageBus->dispatch(new Message(
                $e->getMessage(),
                $e->getCode(),
                $command->getUuid(),
                $command->getAggregateUuid(),
                $e
            ));
        }
    }