@param Command        $command
@param CommandHandler $handler
@param string         $message

@return self
331204
public static function forCommand(Command $command, CommandHandler $handler, string $message = ''): self
    {
        return new static(
            sprintf(
                'The command [%s] could not be handled by [%s].  %s',
                $command::schema()->getId()->toString(),
                get_class($handler),
                $message
            ),
            Code::INTERNAL
        );
    }
347299
public function addHandler(CommandHandlerInterface $handler)
    {
        $this->__queue->enqueue($handler, $handler->getPriority());
        return $this;
    }
1232751
final public function handle(Command $command): void
    {
        if (!$command instanceof ReceivedCommand && $this->discriminator->shouldEnqueue($command)) {
            $this->queue->send($command);

            return;
        }

        if ($command instanceof ReceivedCommand) {
            $command = $command->getOriginalCommand();
        }

        $this->wrappedCommandBus->handle($command);
    }
1259719
public function removeCommandCallback($command, $method)
    {
        $command = strtolower($command);

        if (isset($this->__command_callbacks[$command]) )
        {
            if($method instanceof \Closure) {
                $index = spl_object_hash($method);
            } else {
                $index = $method;
            }

            unset($this->__command_callbacks[$command][$index]);
        }

        return $this;
    }
352305
public function handle(SubscribeSubscriberCommand $command)
    {
        if ($subscriber = Subscriber::where('email', '=', $command->email)->first()) {
            return $subscriber;
        }

        $subscriber = Subscriber::firstOrCreate(['email' => $command->email]);

        // Decide what to subscribe the subscriber to.
        if ($subscriptions = $command->subscriptions) {
            $components = Component::whereIn('id', $subscriptions)->get();
        } else {
            $components = Component::all();
        }

        $components->each(function ($component) use ($subscriber) {
            Subscription::create([
                'subscriber_id' => $subscriber->id,
                'component_id'  => $component->id,
            ]);
        });

        if ($command->verified) {
            execute(new VerifySubscriberCommand($subscriber));
        } else {
            $subscriber->notify(new VerifySubscriptionNotification());
        }

        event(new SubscriberHasSubscribedEvent($subscriber));

        $subscriber->load('subscriptions');

        return $subscriber;
    }
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;
    }
60020
public function registerCommand(CommandInterface $commandHandler)
    {
        $command = strtoupper($commandHandler->getCommand());
        $this->commandHandlers[$command] = $commandHandler;
    }
700619
public static function onCommand($command, ConstraintViolationListInterface $violations)
    {
        $exception = new static(
            'Validation failed for ' . get_class($command) .
            ' with ' . $violations->count() . ' violation(s).'
        );

        $exception->command    = $command;
        $exception->violations = $violations;

        return $exception;
    }
507074
public function toCommandHandler($command)
    {
        $commandClass = get_class($command);
        $handler = substr_replace($commandClass, 'CommandHandler', strrpos($commandClass, 'Command'));

        if ( ! class_exists($handler))
        {
            $message = "Command handler [$handler] does not exist.";

            throw new HandlerNotRegisteredException($message);
        }

        return $handler;
    }
420967
function runCommand($command, callable $onError = null)
    {
        $onError = $onError ?: function () {};

        // Symfony's 4.x Process component has deprecated passing a command string
        // to the constructor, but older versions (which Valet's Composer
        // constraints allow) don't have the fromShellCommandLine method.
        // For more information, see: https://github.com/laravel/valet/pull/761
        if (method_exists(Process::class, 'fromShellCommandline')) {
            $process = Process::fromShellCommandline($command);
        } else {
            $process = new Process($command);
        }

        $processOutput = '';
        $process->setTimeout(null)->run(function ($type, $line) use (&$processOutput) {
            $processOutput .= $line;
        });

        if ($process->getExitCode() > 0) {
            $onError($process->getExitCode(), $processOutput);
        }

        return $processOutput;
    }
362511
protected function configureCommand(Command $command)
    {
        $broker = new MessageBroker();
        $pool = new WorkerPool($this->getConfiguration(), $this->emitter, $broker);
        $runner = new StreamSelectRunner($this->emitter, $pool);
        $command->setRunner($runner);

        $loader = new SuiteLoader($this->getConfiguration()->getGrep(), $this->emitter);
        $command->setLoader($loader);
    }
1026245
public function callHandler(array $command, $method, $args = array())
    {
        try {
            $handlers = $this->getHandlers();
            return Handler::call($handlers, $command['command_id'], $method, $args);
        } catch (Exception $ex) {
            return $ex->getMessage();
        }
    }
983842
public static function make(CommandInterface $command, ProcessOutputInterface $outputHandler = null)
    {
        return new Process($command, null, $outputHandler);
    }
1237859
public static function commandHandlerAlreadyDefinedForCommand(
        $commandClassName,
        CommandHandlerInterface $previous,
        CommandHandlerInterface $current
    ) {
        $message = 'Trying to add handler %3$s handling command %1$s which is already handled by %2$s.';
        if (get_class($previous) === get_class($current)) {
            $message = 'Trying to add multiple handling method for the command %1$s in the handler %2$s';
        }

        return new self(sprintf($message, $commandClassName, get_class($previous), get_class($current)));
    }
20586
public function handle(Message $message, array $args)
    {
        $subCommand = array_shift($args);

        if (array_key_exists($subCommand, $this->subCommands)) {
            return $this->subCommands[$subCommand]->handle($message, $args);
        } elseif (array_key_exists($subCommand, $this->subCommandAliases)) {
            return $this->subCommands[$this->subCommandAliases[$subCommand]]->handle($message, $args);
        }

        if (! is_null($subCommand)) {
            array_unshift($args, $subCommand);
        }

        return call_user_func_array($this->callable, [$message, $args]);
    }
133437
public function unbind($cmd, $handler) {
		if (!empty($this->listeners[$cmd])) {
			foreach ($this->listeners[$cmd] as $i => $h) {
				if ($h === $handler) {
					unset($this->listeners[$cmd][$i]);
					return $this;
				}
			}
		}
		return $this;
	}
339054
public function command($command, $method) {

        self::$commands[] = $command;
        self::$callbacks[$command] = $method;
    }