@param array|\Psr\Http\Message\MessageInterface|string|\UaRequest\GenericRequest $request

@throws \UnexpectedValueException

@return \UaRequest\GenericRequest
174741
private function buildRequest($request): GenericRequest
    {
        if ($request instanceof GenericRequest) {
            $this->logger->debug('request object used as is');

            return $request;
        }

        $requestFactory = new GenericRequestFactory();

        if ($request instanceof MessageInterface) {
            $this->logger->debug('request object created from PSR-7 http message');

            return $requestFactory->createRequestFromPsr7Message($request);
        }

        if (is_array($request)) {
            $this->logger->debug('request object created from array');

            return $requestFactory->createRequestFromArray($request);
        }

        if (is_string($request)) {
            $this->logger->debug('request object created from string');

            return $requestFactory->createRequestFromString($request);
        }

        throw new UnexpectedValueException(
            'the request parameter has to be a string, an array or an instance of \Psr\Http\Message\MessageInterface'
        );
    }
1076628
public function setRequest($request = [])
    {
        if (!empty($request)) {
            if (is_array($request)) {
                foreach ((array) $request as $item) {
                    foreach ($item as $key => $value) {
                        if (empty($value)) {
                            $request['empty'] = 'true';
                        } else {
                            $request['empty'] = 'false';
                        }
                    }
                    break;
                }
                $this->_request = $request;

                return $this;
            } else {
                throw new \Exception('Initial request object must be an instance of an array!');
            }
        } else {
            throw new \Exception('An empty request object was given!');
        }
    }
694726
public function build(HttpRequestInterface $request)
    {
        if ($request instanceof AbstractHttpRequest) {
            $response      = $request->response;
            $this->request = $request;

            if ($request->batch === true) {
                $boundary    = $request->batchBoundary;
                $this->batch = $this->deconstructBatchResponseBody($response, $boundary);
            }
        } else {
            $response = $request;
        }
        $this->splitResponseToHeadersArrayAndBody($response);
        $statusLineArray = explode(' ', trim($this->headers['status'][0]));

        $this->status = (int) $statusLineArray[1];

        //todo: Revisit this:
        if ($this->verboseExtractStatusLine === true) {
            $this->protocol = $statusLineArray[0];

            $this->statusPhrase = $this->decodeGetStatusPhrase($statusLineArray);
        }

        if (in_array((int) $this->status, $this->enabledHttpServerExceptions, true)) {
            // Ignoring this for now.
            // @codeCoverageIgnoreStart
            $this->protocol     = $statusLineArray[0];
            $this->statusPhrase = $this->decodeGetStatusPhrase($statusLineArray);
            throw new ServerException($this->statusPhrase, $this->status);
            // @codeCoverageIgnoreEnd
        }

        //todo: End revisit this:

        return $this;
    }
819980
public function getRequest()
    {
        if(!$this->_request instanceof ControllerRequestInterface)
        {
            //Setup the request
            $this->_request->url  = $this->getIdentifier();
            $this->_request->user = $this->getUser();

            $this->_request = $this->getObject('lib:controller.request', ObjectConfig::unbox($this->_request));

            if(!$this->_request instanceof ControllerRequestInterface)
            {
                throw new \UnexpectedValueException(
                    'Request: '.get_class($this->_request).' does not implement ControllerRequestInterface'
                );
            }
        }

        return $this->_request;
    }
381808
private function createRpbMessage(GetRequest $request)
    {
        $rpbGetReq = new RpbGetBucketReq();

        $rpbGetReq->setBucket($request->bucket);
        $rpbGetReq->setType($request->type);

        return $rpbGetReq;
    }
1259445
public static function requestIsNotValid($request)
    {
        return new self(sprintf(
            'The request must be a string, an array or implement "Psr\Http\Message\RequestInterface" ("%s" given).',
            is_object($request) ? get_class($request) : gettype($request)
        ));
    }
306862
public function add($request)
    {
        if (is_array($request)) {
            array_walk($request, [$this, __METHOD__]);

            return $this;
        }

        if (!$request instanceof Request) {
            throw new InvalidArgumentException('Argument for add() must be of type array or Request.');
        }

        $this->requests[] = $request;

        return $this;
    }
643817
public static function createParser(Service $api)
    {
        static $mapping = [
            'json'      => 'Api\Api\Parser\JsonRpcParser',
            'query'     => 'Api\Api\Parser\QueryParser',
            'rest-json' => 'Api\Api\Parser\RestJsonParser',
            'rest-xml'  => 'Api\Api\Parser\RestXmlParser'
        ];

        $proto = $api->getProtocol();
        
        if (isset($mapping[$proto])) {
            return new $mapping[$proto]($api);
        } 

        throw new \UnexpectedValueException(
            'Unknown protocol: ' . $api->getProtocol()
        );
    }
783884
public function getDeviceForRequest(WURFL_Request_GenericRequest $request)
    {
        $deviceId = $this->deviceIdForRequest($request);
        return $this->getWrappedDevice($deviceId, $request);
    }
1160822
public static function fromRingRequest(array $request)
    {
        $options = [];
        if (isset($request['version'])) {
            $options['protocol_version'] = $request['version'];
        }

        if (!isset($request['http_method'])) {
            throw new \InvalidArgumentException('No http_method');
        }

        return new Request(
            $request['http_method'],
            Core::url($request),
            isset($request['headers']) ? $request['headers'] : [],
            isset($request['body']) ? Stream::factory($request['body']) : null,
            $options
        );
    }
799386
private function getValuesFromRequest(Request $request)
    {
        $values = array_merge($request->query->all(), $request->request->all());
        $contentValues = json_decode($request->getContent(), true);
        if (is_array($contentValues)) {
            $values = array_merge($values, $contentValues);
        }

        return $values;
    }
1132794
public function convertFromRequest(SimplifiedRequest $request)
    {
        return Request::create(
            $request->path,
            $request->method,
            array(),
            array(),
            array(),
            $this->mapHeaderKeys($request->headers),
            $request->content
        );
    }
916883
private function createRpbMessage(PutRequest $request)
    {
        $rpbPutReq = new RpbPutReq();

        $rpbPutReq->setVclock($request->vClock);
        $rpbPutReq->setBucket($request->bucket);
        $rpbPutReq->setType($request->type);

        if ($request->key) {
            $rpbPutReq->setKey($request->key);
        }

        if ($request->w !== null) {
            $rpbPutReq->setW($this->encodeQuorum($request->w));
        }

        if ($request->dw !== null) {
            $rpbPutReq->setDw($this->encodeQuorum($request->dw));
        }

        if ($request->pw !== null) {
            $rpbPutReq->setPw($this->encodeQuorum($request->pw));
        }

        if ($request->returnBody !== null) {
            $rpbPutReq->setReturnBody($request->returnBody);
        }

        if ($request->vClock !== null) {
            $rpbPutReq->setVclock($request->vClock);
        }

        if ( ! $request->content) {
            return $rpbPutReq;
        }

        $rpbContent = new RpbContent();

        $rpbContent->setVtag($request->content->vtag);
        $rpbContent->setValue($request->content->value);
        $rpbContent->setContentType($request->content->contentType);

        foreach ($request->content->indexes as $name => $values) {
            foreach ($values as $v) {
                $value = new RpbPair();

                $value->setKey($name);
                $value->setValue($v);

                $rpbContent->addIndexes($value);
            }
        }

        foreach ($request->content->metas as $name => $meta) {
            $value = new RpbPair();

            $value->setKey($name);
            $value->setValue($meta);

            $rpbContent->addUsermeta($value);
        }

        foreach ($request->content->links as $name => $link) {
            $rpbLink = new RpbLink();

            $rpbLink->setKey($link['key']);
            $rpbLink->setTag($link['tag']);
            $rpbLink->setBucket($link['bucket']);

            $rpbContent->addLinks($rpbLink);
        }

        $rpbPutReq->setContent($rpbContent);

        return $rpbPutReq;
    }
166376
private function getDeviceForRequest(Request\GenericRequest $request)
    {
        Handlers\Utils::reset();

        $deviceId = $this->deviceIdForRequest($request);

        return $this->getWrappedDevice($deviceId, $request);
    }
1094591
public function toArray($request)
    {
        return $this->resource->map(function($value) use($request) {
            return 'local' == config('app.env') && $request->has('__message') ?
            $this->transform($this->message()) : $this->transform($this->template($value));
        });
    }
365922
private function preRequest(string $request): string
    {
        $result = $this->preRequest->handle(new TransportContainer($this, $request));

        if ($result instanceof TransportContainer) {
            return $result->getRequest();
        }

        throw new \RuntimeException();
    }
1137072
public static function requestToString(RequestInterface $request): string
    {
        $httpMethod = $request->getMethod();
        if (empty($httpMethod)) {
            throw new \UnexpectedValueException('Object can not be serialized because HTTP method is empty');
        }
        $headers = self::serializeHeaders($request->getHeaders());
        $body = (string) $request->getBody();
        $format = '%s %s HTTP/%s%s%s';
        if (! empty($headers)) {
            $headers = self::EOL . $headers;
        }
        if (! empty($body)) {
            $headers .= self::EOL . self::EOL;
        }

        return sprintf(
            $format,
            $httpMethod,
            $request->getRequestTarget(),
            $request->getProtocolVersion(),
            $headers,
            $body
        );
    }