Translate a command to its handler counterpart

@param $command
@return mixed
@throws HandlerNotRegisteredException
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;
    }
729015
public function inflect($command, $commandHandler)
    {
        $commandName = get_class($command);

        $start = strpos($commandName, '\\') !== false ? strrpos($commandName, '\\') + 1 : 0;
        $length = strpos($commandName, $this->suffix, -$this->suffixLength) !== false ? $this->suffixLength : null;

        return lcfirst($length ? substr($commandName, $start, -$length) : substr($commandName, $start));
    }
1330399
public function handle($command)
    {
        $message = $this->message->send($command->conversation, $command->body, $command->senderId, $command->type);

        $this->dispatcher->dispatch($this->message->releaseEvents());

        return $message;
    }
618732
public function execute(interfaces\commands\Command $command)
    {
        $handler = $this->resolver->resolve($command);
        
        return call_user_func([$handler, 'handle'], $command);
    }
362454
public function exec($command)
    {
        $this->_events[] = $event = new Event($this->_mutex, $command);
        return $event;
    }
730360
function unregisterCommand(\CharlotteDunois\Livia\Commands\Command $command) {
        $group = $this->resolveGroup($command->groupID);
        $group->commands->delete($command->name);
        $this->commands->delete($command->name);
        
        $this->client->emit('debug', 'Unregistered command '.$command->groupID.':'.$command->name);
        $this->client->emit('commandUnregister', $command, $this);
        
        return $this;
    }
775505
protected function _commandEnable($command)
    {
        $entity = $this->getController()->getItem();
        $label = AnTranslator::_('LIB-AN-ACTION-'.strtoupper($entity->enabled ? 'disable' : 'enable'));

        $command->append(array('label' => $label))
        ->href($entity->getURL().'&action='.($entity->enabled ? 'disable' : 'enable'))
        ->setAttribute('data-trigger', 'Submit');
    }
769013
public static function parseAndRunCommand($command)
    {
        try {
            list($class, $method, $args) = TaskManager::parseCommand($command);
            if (!class_exists($class)) {
                TaskLoader::loadController($class);
            }

            $obj = new $class();
            if (!method_exists($obj, $method)) {
                throw new TaskManagerException('method ' . $method . ' not found in class ' . $class);
            }

            return call_user_func_array(array($obj, $method), $args);
        } catch (\Exception $e) {
            echo 'Caught an exception: ' . get_class($e) . ': ' . PHP_EOL . $e->getMessage() . PHP_EOL;
            return false;
        }
    }
867428
public function handle($command)
    {
        $ticket = $this->openTicket->by($command->userId)->withText($command->body)->get();
        $this->ticketRepository->save($ticket);

        $this->dispatchEventsFor($this->openTicket);

        return $ticket;
    }
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);
    }
1017823
public function getProcessByCommand(string $command) : Process {
        if( ! array_key_exists($command, $this->processes) ) {
            $this->watch($command);
        }

        foreach($this->getWatchedProcesses() as $process) {
            if($process->getCommand() === $command) {
                return $process;
            }
        }
    }
784089
public function command($command)
    {
        if (!in_array($command, ['start', 'stop', 'restart', 'reload', 'force-reload', 'status'])) {
            throw new \InvalidArgumentException($command);
        }

        $command = 'sudo /etc/init.d/tor '.$command;
        $command = new Command($command);
        $command->execute();

        return $command;
    }
1167916
public function get($command) {
        return isset($this->_commands[$command]) ?
            $this->_commands[$command] :
            null;
    }
511150
public function inflect(ICommand $command)
    {
        $tmpClass = str_replace('Domain', 'Application', get_class($command));
        $handlerClass = str_replace('Command', 'Handler', $tmpClass);

        return $handlerClass;
    }
747062
function execute($command) {
        $output = array();
        $result = null;

        // Redirect standard error to stdout so we can do something with
        // it.
        $command .= " 2>&1";

        exec($command, $output, $result);

        if ($result !== 0) {
            if ($result === self::RESULT_CODE_COMMAND_NOT_FOUND) {
                throw new CommandNotFoundError(implode("\t", $output), $result);
            }
            else {
                throw new ExecutionError(implode("\t", $output), $result);
            }
        }
        return $output;
    }
651131
public function resolveHandler($command)
    {
        if ($command instanceof SelfHandling) {
            return $command;
        }

        return $this->container->make($this->getHandlerClass($command));
    }
1238818
public function getCommand($command): Command
    {
        if (isset($this->aliases[$command])) {
            return $this->aliases[$command];
        }

        if (isset($this->commands[$command])) {
            return $this->commands[$command];
        }

        throw new CommandNotFoundException($this, $command);
    }