Calculate the href for a command.

@param CommandInterface $command The command.
@param ModelInterface   $model   The current model.

@return string
494661
private function calculateHref(CommandInterface $command, $model)
    {
        $parameters = $this->calculateParameters($command, ModelId::fromModel($model)->getSerialized());
        $href       = '';
        foreach ($parameters as $key => $value) {
            $href .= \sprintf('&%s=%s', $key, $value);
        }

        return $this->addToUrl($href);
    }
225009
protected function generateCommandUrl(string $command, array $parameters = [])
    {
        $query = '';
        if (!empty($parameters)) {
            $query = '?' . http_build_query($parameters);
        }

        return $this->ssoServerUrl . '/sso/' . $command . $query;
    }
930155
protected function _commandView($command)
    {
        $entity = $this->getController()->getItem();
        $label = sprintf(AnTranslator::_('COM-STORIES-VIEW-ALL-COMMENTS'), $entity->getNumOfComments());
        $command->append(array('label' => $label));
        $command->href(route($entity->getURL()));
    }
1237604
protected function conditionMatched(CommandInterface $command): bool
    {
        $matchedConditions = true;
        foreach ($command->getConditions() as $condition) {
            if (!$condition->match($this->commandExitCodes)) {
                $matchedConditions = false;
            }
        }

        return $matchedConditions;
    }
1311277
public function after(
        CommandInterface $command,
        RequestInterface $request,
        Operation $operation
    ) {
        $additional = $operation->getAdditionalParameters();
        if ($additional && $additional->getLocation() == $this->locationName) {
            foreach ($command->toArray() as $key => $value) {
                if (!$operation->hasParam($key)) {
                    $uri = $request->getUri();
                    $query = Psr7\parse_query($uri->getQuery());

                    $query[$key] = $this->prepareValue(
                        $value,
                        $additional
                    );

                    $uri = $uri->withQuery($this->querySerializer->aggregate($query));
                    $request = $request->withUri($uri);
                }
            }
        }

        return $request;
    }
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;
    }
933426
protected function execute(CommandInterface $command)
    {
        $runner = $this->getCommandRunner();

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

        $this->checkReturnValue($runner);
    }
1086780
protected function getKeyFromGeoradiusCommands(CommandInterface $command)
    {
        $arguments = $command->getArguments();
        $argc = count($arguments);
        $startIndex = $command->getId() === 'GEORADIUS' ? 5 : 4;

        if ($argc > $startIndex) {
            $keys = array($arguments[0]);

            for ($i = $startIndex; $i < $argc; ++$i) {
                $argument = strtoupper($arguments[$i]);
                if ($argument === 'STORE' || $argument === 'STOREDIST') {
                    $keys[] = $arguments[++$i];
                }
            }

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

        return $arguments[0];
    }
875999
protected function createRequest(CommandInterface $command)
    {
        $operation = $command->getOperation();
        $client = $command->getClient();
        $options = $command[AbstractCommand::REQUEST_OPTIONS] ?: array();

        // If the command does not specify a template, then assume the base URL of the client
        if (!($uri = $operation->getUri())) {
            return $client->createRequest($operation->getHttpMethod(), $client->getBaseUrl(), null, null, $options);
        }

        // Get the path values and use the client config settings
        $variables = array();
        foreach ($operation->getParams() as $name => $arg) {
            if ($arg->getLocation() == 'uri') {
                if (isset($command[$name])) {
                    $variables[$name] = $arg->filter($command[$name]);
                    if (!is_array($variables[$name])) {
                        $variables[$name] = (string) $variables[$name];
                    }
                }
            }
        }

        return $client->createRequest($operation->getHttpMethod(), array($uri, $variables), null, null, $options);
    }
758856
protected function _commandView($command)
    {
        $entity = $this->getController()->getItem();
        $command->append(array('label' => AnTranslator::_('COM-ARTICLES-ARTICLE-CURRENT-VERSION')));
        $command->href('option=com_articles&view=article&id='.$entity->parent->id);
    }
805130
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');
            }
        }

        $this->objectManager->persist($object);
        $this->objectManager->flush();
    }
1081153
protected function renderModel(ModelInterface $model, EnvironmentInterface $environment)
    {
        $event = new ParentViewChildRecordEvent($environment, $model);
        $environment->getEventDispatcher()->dispatch($event::NAME, $event);

        if (null !== $event->getHtml()) {
            $information = [
                [
                    'colspan' => 1,
                    'class'   => 'tl_file_list col_1',
                    'content' => $event->getHtml()
                ]
            ];
            $model->setMeta($model::LABEL_VALUE, $information);
            return;
        }

        parent::renderModel($model, $environment);
    }
54513
protected function _commandDelete($command)
    {
        $entity = $this->getController()->getItem();

        $name = AnInflector::pluralize($this->getController()->getIdentifier()->name);
        $redirect = 'option=com_'.$this->getIdentifier()->package.'&view='.$name;

        $command->append(array('label' => AnTranslator::_('LIB-AN-ACTION-DELETE')))
        ->href(route($entity->getURL()))
        ->setAttribute('data-action', 'delete')
        ->setAttribute('data-redirect', route($redirect))
        ->class('action-delete');
    }
997232
private function generateToggleUrl(ModelInterface $model)
    {
        $toggleUrlEvent = new AddToUrlEvent(
            'ptg=' . $model->getId() . '&amp;provider=' . $model->getProviderName()
        );
        $this->getEnvironment()->getEventDispatcher()->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, $toggleUrlEvent);

        return System::getContainer()->get('router')->generate(
            'cca_dc_general_tree_toggle',
            $this->getQueryParameterFromUrl($toggleUrlEvent->getUrl()),
            UrlGenerator::ABSOLUTE_URL
        );
    }
910389
protected function setPreCommand(CommandInterface $command, array $definition)
    {
        if (isset($definition[static::CONFIG_PRE_COMMAND])) {
            $command->setPreCommand($definition[static::CONFIG_PRE_COMMAND]);
        }
    }
303840
public function run(CommandInterface $command, $result = null)
    {
        $key = $command->getRequestMethod() === 'GET' ? 'query' : 'body';
        $options = [$key => []];

        if(!empty($params = $command->getParams())) {
            $options[$key] = array_merge($options[$key], $params);
        }

        if($config = $this->getConfig()) {
            if(!empty($config->getSteamKey())) {
                $options[$key]['key'] = $config->getSteamKey();
            }

            $this->urlBuilder->setBaseUrl($config->getBaseSteamApiUrl());
        }

        $request = new Request(
            $command->getRequestMethod(),
            $this->urlBuilder->build($command)
        );

        return $this->client->sendAsync($request, $options);
    }
238599
public function parse(CommandInterface $command)
    {
        $response = $command->getRequest()->getResponse();

        // If there is no response or Body, just return it
        if ($response === null || !$response->getBody()) {
            return $response;
        }

        $responseArray = $this->parseResponseIntoArray($response);

        // Handle multi-result responses
        if (array_key_exists('results', $responseArray)) {
            return $this->createMultiResultResponse($response);
        }

        return $this->createSingleResultResponse($response);
    }