@param ICommand $command
@param bool $allowParallelism

@return string
332983
public function lockCommand(ICommand $command, $allowParallelism = true) {
        if ($command->isParallel() && $allowParallelism) {
            return;
        }

        if ($this->isLocked($command->getName())) {
            throw new CommandIsAlreadyRunningException(s(
                'Command "%s" is already being executed. ' .
                'Parallel execution for this command has been forbidden. ' .
                'This is the corresponding lock file "%s".',
                $command->getName(),
                $this->getLockName($command->getName())
            ));
        }

        return $this->createLock($command->getName());
    }
958712
final public function handle(Command $command): void
    {
        $supportedCommandType = $this->getSupportedCommandType();
        if (!\is_a($command, $supportedCommandType)) {
            throw new InvalidCommandException(\sprintf(
                'Command must be a %s, %s given',
                $supportedCommandType,
                \get_class($command)
            ));
        }

        $this->handleCommand($command);
    }
1232318
private function apiCall($command, $data=array()) {
			if (!isset($this->rest_commands[$command])) {
				return false;
			}

			$cmd = $this->rest_commands[$command];

			$url = $cmd['url'];
			$url = str_replace(array('{k}', '{s}') ,array($this->nx_key, $this->nx_secret), $url);

			$parsed_data = array();
			foreach ($data as $k => $v) $parsed_data['{'.$k.'}'] = $v;
			$url = str_replace(array_keys($parsed_data) ,array_values($parsed_data), $url);

			$url = trim($this->rest_base_url, '/') . $url;
			$post_data = '';

			// If available, use CURL
			if (function_exists('curl_version')) {

				$to_nexmo = curl_init( $url );
				curl_setopt( $to_nexmo, CURLOPT_RETURNTRANSFER, true );
				curl_setopt( $to_nexmo, CURLOPT_SSL_VERIFYPEER, false);
				curl_setopt($to_nexmo, CURLOPT_HTTPHEADER, array('Accept: application/json'));

				if ($cmd['method'] == 'POST') {
					curl_setopt( $to_nexmo, CURLOPT_POST, true );
					curl_setopt( $to_nexmo, CURLOPT_POSTFIELDS, $post_data );
				}

				$from_nexmo = curl_exec( $to_nexmo );
				$curl_info = curl_getinfo($to_nexmo);
				$http_response_code = $curl_info['http_code'];
				curl_close ( $to_nexmo );

			} elseif (ini_get('allow_url_fopen')) {
				// No CURL available so try the awesome file_get_contents

				$opts = array('http' =>
					array(
						'method'  => 'GET',
						'header'  => 'Accept: application/json'
					)
				);

				if ($cmd['method'] == 'POST') {
					$opts['http']['method'] = 'POST';
					$opts['http']['header'] .= "\r\nContent-type: application/x-www-form-urlencoded";
					$opts['http']['content'] = $post_data;
				}

				$context = stream_context_create($opts);
				$from_nexmo = file_get_contents($url, false, $context);

				// et the response code
				preg_match('/HTTP\/[^ ]+ ([0-9]+)/i', $http_response_header[0], $m);
				$http_response_code = $m[1];

			} else {
				// No way of sending a HTTP post :(
				return false;
			}

			$data = json_decode($from_nexmo, true);
			return array(
				'data' => $data,
				'http_code' => (int)$http_response_code
			);

		}
93307
private function phpCommand($command, $params = [], $context = [])
    {
        $contextParams = [];
        foreach ($context as $arg=>$val)
        {
            $contextParams[] = '--' . $arg . '=' . $val;
        }

        return implode(' ', array_merge(
            [ PHP_BINARY, realpath($this->scriptRoot . DIRECTORY_SEPARATOR . $command) ],
            $params,
            $contextParams
        ));
    }
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);
    }
1326695
protected function getUrl(Command $command)
    {
        return $this->url
            .(stripos($this->url, '?') !== false ? '&' : '?')
            .http_build_query([self::COMMAND => $command->getName()]);
    }
518105
public function execute($command, callable $next)
    {
        $constraintViolations = $this->validator->validate($command);

        if (count($constraintViolations) > 0) {
            throw InvalidCommandException::onCommand($command, $constraintViolations);
        }

        return $next($command);
    }
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);
    }
34142
private function getCommandLabel(CommandInterface $command)
    {
        if (null === $label = $command->getLabel()) {
            $label = $command->getName();
        }

        $label = $this->translate($label);

        return \is_array($label) ? $label[0] : $label;
    }
682467
protected function formattedCommand($command)
    {
        $structure = [
            $this->getEnvVariable(),
            $this->executable,
            $this->getOptions(),
            $command
        ];

        return implode(' ', array_filter($structure));
    }
811219
public function registerCommand($command, $callable, array $options = [])
    {
        if (array_key_exists($command, $this->commands)) {
            throw new \Exception("A command with the name {$command} already exists.");
        }

        list($commandInstance, $options) = $this->buildCommand($command, $callable, $options);
        $this->commands[$command]        = $commandInstance;

        foreach ($options['aliases'] as $alias) {
            $this->addCommandAlias($alias, $command);
        }

        return $commandInstance;
    }
445981
protected function renderItem($command)
    {
        if (!($command instanceof AbstractCommand)) {
            throw new \InvalidArgumentException('Command descriptor need Command object to describe it.');
        }

        /** @var Command $command */
        $name = $command->getName();
        $description = $command->getDescription() ?: 'No description';

        $template = str_replace('{WIDTH}', $this->maxLength + $this->offsetAfterCommand, $this->template);

        // Sets the body indent.
        $body = [];

        $description = explode("\n", $description);

        $line1 = array_shift($description);
        $body[] = sprintf($template, $name, $line1);

        foreach ($description as $line) {
            $line = trim($line);
            $line = sprintf($template, '', $line);
            $body[] = $line;
        }

        return implode("\n", $body);
    }
1275535
public function execute($command, callable $next)
    {
        try {
            return $next($command);
        } catch (ExceptionInterface $exception) {
            throw $exception;
        } catch (ValidationException $exception) {
            $this->exceptionHandler->throwServiceExceptionFromViolationException($exception);
        } catch (RequestException $exception) {
            $this->exceptionHandler->throwServiceExceptionFromRequestException($exception);
        } catch (\Throwable $exception) {
            $this->exceptionHandler->throwServiceException($exception);
        }
    }
536814
public function get(string $name) : ICommand
    {
        if (!$this->has($name)) {
            throw new InvalidArgumentException("No command with name \"$name\" exists");
        }

        return $this->commands[$name];
    }
705362
protected function _GetAuthorizeUrl(iApiCommand $command)
    {
        $serverUrl = $this->_getServerUrlEndpoints($command);

        $authUrl = \Poirot\Http\appendQuery(
            $serverUrl
            , \Poirot\Http\buildQueryString( iterator_to_array($command) )
        );

        $response = new Response( $authUrl );
        return $response;
    }
770469
protected static function _compileCommand($command,array $params){
        $s = $w = [];
        foreach ($params as $p) {
            if ($p instanceof static) {
              $s[] = '$('.$p->getShellCommand().')';
            } else if (is_array($p)) foreach ($p as $key => $value) {
                if(is_numeric($key)){
                  $w[] = '--'.$value;
                } else {
                  if(is_bool($value)){
                     if($value) $w[] = '--'.$key;
                  } else {
                    $w[] = '--'.$key.'='.escapeshellarg($value);
                  }
                }
            } else {
              $s[] = $p;
            }
        }
        return trim(
            '/usr/bin/env '.$command.' '.implode(' ',array_merge($w,$s))
        );
    }
423672
protected function buildHref(CommandInterface $command)
    {
        $arrParameters = (array) $command->getParameters();
        $strHref       = '';

        foreach ($arrParameters as $key => $value) {
            $strHref .= \sprintf('&%s=%s', $key, $value);
        }

        return $strHref;
    }