@param CommandInterface $command
@param RequestInterface $request
@param Operation        $operation

@return RequestInterface
518724
public function after(
        CommandInterface $command,
        RequestInterface $request,
        Operation $operation
    ) {
        foreach ($this->buffered as $param) {
            $this->visitWithValue(
                $command[$param->getName()],
                $param,
                $operation
            );
        }

        $this->buffered = [];

        $additional = $operation->getAdditionalParameters();
        if ($additional && $additional->getLocation() == $this->locationName) {
            foreach ($command->toArray() as $key => $value) {
                if (!$operation->hasParam($key)) {
                    $additional->setName($key);
                    $this->visitWithValue($value, $additional, $operation);
                }
            }
            $additional->setName(null);
        }

        // If data was found that needs to be serialized, then do so
        $xml = '';
        if ($this->writer) {
            $xml = $this->finishDocument($this->writer);
        } elseif ($operation->getData('xmlAllowEmpty')) {
            // Check if XML should always be sent for the command
            $writer = $this->createRootElement($operation);
            $xml = $this->finishDocument($writer);
        }

        if ($xml !== '') {
            $request = $request->withBody(Psr7\stream_for($xml));
            // Don't overwrite the Content-Type if one is set
            if ($this->contentType && !$request->hasHeader('Content-Type')) {
                $request = $request->withHeader('Content-Type', $this->contentType);
            }
        }

        $this->writer = null;

        return $request;
    }
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);
    }
1324448
public function visit(
        CommandInterface $command,
        RequestInterface $request,
        Parameter $param
    ) {
        $value = $command[$param->getName()];

        return $request->withHeader($param->getWireName(), $param->filter($value));
    }
415692
public static function fromCommand(CommandInterface $command)
	{
		$file = new self();
		$file->setParameters($command->getResponse()->json() + array('path' => $command['path']));
		$file->finishUpload();
		return $file->getParameters();
	}
947295
protected function onErrorResponse(CommandInterface $command, ErrorResponseInterface $error)
    {
        $details = explode(' ', $error->getMessage(), 2);

        switch ($details[0]) {
            case 'MOVED':
                return $this->onMovedResponse($command, $details[1]);

            case 'ASK':
                return $this->onAskResponse($command, $details[1]);

            default:
                return $error;
        }
    }
299629
public function execute($operationConfig, $operationMetadata, $inputMap) {
        $request = $this->getRequest($operationConfig, $operationMetadata, $inputMap);

        try {
            $response = $this->client->send($request, array_merge(ApiConfig::getProxy(), ApiConfig::getTimeout()));
            $statusCode = $response->getStatusCode();
            $responseContent = $response->getBody()->getContents();
            
            if ($statusCode < self::HTTP_AMBIGUOUS) {
                
                if (ApiConfig::isDebug()) {
                    $this->logger->debug("---------------------");
                    $this->logger->debug(">>request(".$request->getMethod().") ". $request->getUri()->__toString() );    
                    $this->logger->debug(">>headers: ", $request->getHeaders());
                    $this->logger->debug(">>body: ". $request->getBody());
                    
                    $this->logger->debug("<<statusCode: ". $statusCode);
                    $this->logger->debug("<<headers: ", $response->getHeaders());
                    $this->logger->debug("<<body: ". $responseContent);
                    $this->logger->debug("---------------------");
                }
                
                if (strlen($responseContent) > 0) {
                    return json_decode($responseContent, true);
                } else {
                    return array();
                }
            } else {
                $this->handleException($response, $request);
            }
        } catch (RequestException $ex) {
            if ($ex->hasResponse()) {
                $this->handleException($ex->getResponse(), $request);
            } else {
                throw new ApiException($ex->getMessage());
            }
        }
    }
954568
public function run($command, $operation = 'default')
	{
		$this->output = null;

		try {
			$this->processInstance->setCommandLine($command);
			$this->processInstance->setTimeout(self::PROCESS_TIMEOUT);
			$this->processInstance->run();

			if (!$this->processInstance->isSuccessful()) {
				$this->output = $this->processInstance->getErrorOutput();

				return false;
			}
		} catch (Exception $exception) {
			$message = 'An error occurred that prevented the operation ' . $operation . ': ' . $exception->getMessage();

			switch ($operation) {
				case 'export':
					throw new BackupExportException($message);
				case 'restore':
					throw new BackupRestoreException($message);
				default:
					throw new BackupException($message);
			}
		}

		return true;
	}
259623
public function handle(RequestInterface $request): RequestInterface
    {
        return
            $request->withHeader(
                'Authorization',
                sprintf('Basic %s', base64_encode(sprintf('%s:%s', $this->user, $this->password)))
            );
    }
127037
public function bulkAction(Request $request): BulkOperationResponse
    {
        /** @var \EzSystems\EzPlatformAdminUi\REST\Value\BulkOperation $operationList */
        $operationList = $this->inputDispatcher->parse(
            new Message(
                ['Content-Type' => $request->headers->get('Content-Type')],
                $request->getContent()
            )
        );

        $responses = [];
        foreach ($operationList->operations as $operationId => $operation) {
            $response = $this->httpKernel->handle(
                $this->buildSubRequest($request, $operation),
                HttpKernelInterface::SUB_REQUEST
            );

            $responses[$operationId] = new OperationResponse(
                $response->getStatusCode(),
                $response->headers->all(),
                $response->getContent()
            );
        }

        return new BulkOperationResponse($responses);
    }
1055162
final public function handle(CommandInterface $command)
    {
        $this->validateCommand($command);

        try {
            // @todo - Update this to return the succes event object, rather than using the getSuccessEvent() method
            $this->_handle($command);
        } catch (\Exception $exception) {

            // Log exception
            $commandClass = get_class($command);
            $this->logError(
                "Exception throw while handling {$commandClass} command... {$exception->getMessage()}\n",
                $exception
            );

            // Fire failure event
            $this->emit($this->getFailureEvent($exception));

            throw $exception;
        }

        $event = $this->getSuccessEvent($command);
        $this->emit($event);
    }
299820
protected function prepareCommand(CommandInterface $command)
    {
        // Set the client and prepare the command
        $request = $command->setClient($this)->prepare();
        // Set the state to new if the command was previously executed
        $request->setState(RequestInterface::STATE_NEW);
        $this->dispatch('command.before_send', array('command' => $command));

        return $request;
    }
337159
public function process($src, OperationInterface $operation)
    {
        $callable = $operation->getCallback();
        $arguments = array_merge([$src], $operation->getArguments());
        $res = call_user_func_array($callable, $arguments);
        return $res ?: $src;
    }
461596
public function visit(
        CommandInterface $command,
        RequestInterface $request,
        Parameter $param
    ) {
        $this->jsonData[$param->getWireName()] = $this->prepareValue(
            $command[$param->getName()],
            $param
        );

        return $request->withBody(Psr7\stream_for(\GuzzleHttp\json_encode($this->jsonData)));
    }
723741
protected function populateRequestEventData(
        CommandInterface $cmd,
        RequestInterface $request,
        array $event
    ) {
        $dataFormat = static::getRequestData($request);
        foreach ($dataFormat as $eventKey => $value) {
            if ($value !== null) {
                $event[$eventKey] = $value;
            }
        }
        return $event;
    }
490124
public function modify(RequestInterface $request) : RequestInterface
    {
        /** @var RequestModifierInterface $modifier */
        foreach ($this->collection as $modifier) {
            $request = $modifier->modify($request);
        }

        return $request;
    }
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);
    }
276775
public function getRequestParameters(ServerRequestInterface $httpRequest, Operation $operation): \stdClass
    {
        $indexed = array_combine(
            explode('/', trim($operation->getPath(), '/')),
            explode('/', trim($httpRequest->getUri()->getPath(), '/'))
        );

        $pathParams = [];

        foreach ($indexed as $key => $value) {
            if (0 == strpos('{', $key)) {
                $pathParams[trim($key, '{}')] = $value;
            }
        }

        $queryParams = $httpRequest->getQueryParams();
        $headers     = $httpRequest->getHeaders();

        return $this->assemble(
            $operation,
            $queryParams,
            $pathParams,
            $headers,
            $httpRequest->getParsedBody()
        );
    }