Handle command response.

@param ResponseInterface    $response
@param ApiResourceInterface $owner

@return mixed
511094
public function handleResponse(ResponseInterface $response, ApiResourceInterface $owner)
    {
        $className = $this->resourceClass();

        return $className::createFromResponse($response, $owner->getApi(), $owner);
    }
950680
protected function emitResponse(ResponseInterface $response) {
        $this->logger->flush();
        (new \Zend\HttpHandlerRunner\Emitter\SapiEmitter())->emit($response);
    }
163340
private function handleRedirect(ResponseInterface $response): ResponseInterface
    {
        if ($this->debugbar->isDataPersisted() || session_status() === PHP_SESSION_ACTIVE) {
            $this->debugbar->stackData();
        }

        return $response;
    }
131435
protected function handleResponse(ResponseInterface $response): ResponseInterface
    {
        $contentType = $response->getHeader('Content-Type');

        if (in_array(self::CONTENT_TYPE_JSON_API, $contentType, true)) {
            $stream = $response->getBody();

            return new JsonApiResponse(
                $response->getStatusCode(),
                $response->getHeaders(),
                $this->streamToDocument($stream)
            );
        }

        return $response;
    }
1069472
private function handleResponse($response)
    {
        if ($this->client->newFormatModeEnabled === true) {
            return $response;
        }

        return $this->client->handleHttpResponse($response);
    }
886165
protected function send(
        ResponseInterface $response,
        string $body): ResponseInterface
    {
        if (!$body) {
            $response = $this->sendErrorDocument($response);
        }
        unset($this->errorDocument);
        $response = $response->withHeader(
            Response::HEADER_CONTENT_LENGTH,
            (string) strlen($body));
        header(Response::PROTOCOL
             . $response->getProtocolVersion() . " "
             . $response->getStatusCode() . " "
             . $response->getReasonPhrase());
        foreach ($response->getHeaders() as $key => $value) {
            header($key . ": " . implode("; ", $value));
        }
        $response->getBody()->write($body);
        return $response;
    }
593041
protected function handleResponse(ResponseInterface $response)
    {
        $responseWrapper = new Response($response);
        $statusCode = (int) floor($response->getStatusCode() / 100);

        if ($statusCode === 4) {
            throw new ClientException($responseWrapper);
        } elseif ($statusCode === 5) {
            throw new ServerException($responseWrapper);
        }

        return $responseWrapper;
    }
978334
public function respond( ResponseInterface $response ) {
		if ( ! headers_sent() ) {
			$this->sendHeaders( $response );
		}
		$this->sendBody( $response );
	}
1332088
public function sendHeaders( ResponseInterface $response ) {
		// Status
		header( sprintf(
			'HTTP/%s %s %s',
			$response->getProtocolVersion(),
			$response->getStatusCode(),
			$response->getReasonPhrase()
		) );

		// Headers
		foreach ( $response->getHeaders() as $name => $values ) {
			foreach ( $values as $value ) {
				header( sprintf( '%s: %s', $name, $value ), false );
			}
		}
	}
354767
protected function appendAllResponse(ResponseInterface $response): ResponseInterface
    {
        if ($this->append) {
            $this->cors->setResponse('psr-7', $response);
            $this->cors->handle();

            return $this->cors->getResponse();
        }

        return $response;
    }
580572
protected function handleErrors(ResponseInterface $response)
    {
        $statusCode = $response->getStatusCode();
        switch ($statusCode) {
            case 400:
                throw HttpClientException::badRequest($response);
            case 401:
                throw HttpClientException::unauthorized($response);
            case 402:
                throw HttpClientException::requestFailed($response);
            case 404:
                throw HttpClientException::notFound($response);
            case 413:
                throw HttpClientException::payloadTooLarge($response);
            case 500 <= $statusCode:
                throw HttpServerException::serverError($statusCode);
            default:
                throw new UnknownErrorException();
        }
    }
1130058
protected function handleErrors(ResponseInterface $response)
    {
        $body = $response->getBody()->__toString();
        switch ($response->getStatusCode()) {
            case 400:
                throw new DomainExceptions\BadRequestException($body);
                break;

            case 403:
                throw new DomainExceptions\ForbiddenException();
                break;

            case 404:
                throw new DomainExceptions\NotFoundException();
                break;

            case 500:
                throw new DomainExceptions\ServerErrorException();
                break;

            default:
                throw new DomainExceptions\UnknownErrorException();
                break;
        }
    }
424363
private function runCmd(DriverInterface $driver, $cmd, array $args, Response $response)
    {
        $data = null;
        try {
            if ($driver->isAllowedCommand($cmd)) {
                $data = call_user_func_array(
                    array($driver, $cmd),
                    $this->getArgs($args, $cmd, $response, $driver->getDriverId())
                );
            } else {
                $this->error(sprintf('command "%s" not allowed', $cmd));
            }
        } catch (Exception $e) {
            $this->error($e->getMessage());
        }

        return $data instanceof HttpResponse ? $data : $response;
    }
190274
protected function executeOn(ApiResourceInterface $resource)
    {
        $response = $this->execute($resource);

        if (method_exists($this, 'handleResponse')) {
            return $this->handleResponse($response, $resource);
        }

        return true;
    }
67382
public function processResponse(ResponseInterface $response)
    {
        if (!$response instanceof Response
            || !$this->getRequest()
        ) {
            return;
        }

        $response = $this->handleResponse($response);
        $this->renderResponse($response);
        $this->terminateApp();
    }
1306307
public function processResponse(ResponseInterface $response, SystemEvent $event)
    {
        if ($event->getName() === SystemEvent::FINISH) {
            $event->stopPropagation(true);
            $server  = $this->getServer();
            $emitter = $server->getEmitter();
            $emitter->emit($response);

            return;
        }
        $events = $this->getEvents();
        $event->setResult(SystemEvent::FINISH, $response);
        $events->trigger($event(SystemEvent::FINISH));
    }
1171870
private function transformResponseToResult(
        ResponseInterface $response,
        RequestInterface $request,
        CommandInterface $command
    ) {
        $transform = $this->responseToResultTransformer;

        return $transform($response, $request, $command);
    }