@param ServerRequestInterface $serverRequest

@return StreamedPart
963927
public static function convert(ServerRequestInterface $serverRequest)
    {
        $stream = fopen('php://temp', 'rw');

        foreach ($serverRequest->getHeaders() as $key => $values) {
            foreach ($values as $value) {
                fwrite($stream, "$key: $value\r\n");
            }
        }
        fwrite($stream, "\r\n");

        $body = $serverRequest->getBody();
        $body->rewind();

        while (!$body->eof()) {
            fwrite($stream, $body->read(1024));
        }

        rewind($stream);

        return new StreamedPart($stream);
    }
607452
public function convert(BrowserKitRequest $request, ServerRequestInterface $baseRequest)
    {
        $stream = $this->createStream($request);
        list($uri, $queryParams) = $this->buildFullUri($request);
        
        if ($baseRequest instanceof ServerRequest) {
            $serverParams = $this->determineServerParams($request, $uri, (array)$queryParams);
            $psrRequest = $baseRequest->withServerParams($request->getServer() + $serverParams);
        } else {
            $psrRequest = $this->setRequestHeaders($baseRequest, $request->getServer());
        }
        
        return $this->setRequestProperties($psrRequest, $request, $stream, $uri, (array)$queryParams);
    }
276880
private function createFakeRequest(ServerRequestInterface $psrRequest): Request
    {
        $server = [];
        $uri = $psrRequest->getUri();

        if ($uri instanceof UriInterface) {
            $server['SERVER_NAME'] = $uri->getHost();
            $server['SERVER_PORT'] = $uri->getPort();
            $server['REQUEST_URI'] = $uri->getPath();
            $server['QUERY_STRING'] = $uri->getQuery();
        }

        $server['REQUEST_METHOD'] = $psrRequest->getMethod();

        $server = \array_replace($server, $psrRequest->getServerParams());

        $parsedBody = $psrRequest->getParsedBody();
        $parsedBody = \is_array($parsedBody) ? $parsedBody : [];

        $request = new Request(
            $psrRequest->getQueryParams(),
            $parsedBody,
            $psrRequest->getAttributes(),
            $psrRequest->getCookieParams(),
            [],
            $server,
            ''
        );

        $request->headers->replace($psrRequest->getHeaders());

        return $request;
    }
884688
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
    {
        $operation = $this->getOperation($request);

        foreach ($operation->getParameters() as $parameter) {
            $name    = $parameter->getName();
            $request = $request->withAttribute(
                $name,
                $this->processorBuilder
                    ->build($this->getOperation($request)->getParameter($name)->getSchema())
                    ->hydrate($request->getAttribute($name))
            );
        }

        return $delegate->process($request);
    }
1273753
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
    {
        $contentType = $request->getHeaderLine('Content-Type');

        if (!$this->match($contentType)) {
            return $delegate->process($request);
        }

        $rawBody = (string)$request->getBody();
        $parsedBody = json_decode($rawBody, true);

        if (!empty($rawBody) && json_last_error() !== JSON_ERROR_NONE) {
            $statusCode = 400;
            $apiMessage = new HttpStatusCodeApiMessage($statusCode);
            $apiMessage->setCode('invalid-json');
            $apiMessage->setValue('Invalid JSON');
            $apiResponse = $this->newPsrResponseWithTranslatedMessages->__invoke(
                null,
                $statusCode,
                $apiMessage
            );

            return $apiResponse;
        }

        $request = $request
            ->withAttribute('rawBody', $rawBody)
            ->withParsedBody($parsedBody);

        return $delegate->process($request);
    }
1248524
public function createStream($serverconfig = null)
    {
        if ($serverconfig == null) {
            $serverconfig = $this->default_streamserver_config;
        }
        $stream = new $this->stream_class;
        $stream->setRtmpServer($this->streamserver_config[$serverconfig]['rtmp_url']);
        $stream->setRtmpApp($this->streamserver_config[$serverconfig]['app']);
        return $stream;
    }
241096
public function getDispatcher(ServerRequestInterface $request)
    {
        // NOTE: We don't need to worry about setting the
        // strategy the container does that for us.

        $this->prepRoutes($request);

        return (new FructifyDispatcher($this->getData()))
        ->setStrategy($this->getStrategy());
    }
1221026
public function handle(ServerRequestInterface $request): ResponseInterface{
        $routing        = $this->getRouteCollector()
            ->router($request->getUri()->getHost(), $request->getMethod())
            ->search($request->getUri()->getPath())
        ;
        $handlerBuilder = $kernel->getRequestHandlerBuilder();

        if($routing->found){
            $method = $routing->data["action"]["method"];
            $object = $kernel->getContainer()->getInstance(
                $routing->data["action"]["class"]
            );
            $action = [$object, $method];

            if($object instanceof Bundle\MiddlewareRegisterInterface){
                $object->middlewareRegister($handlerBuilder);
            }
        }else{
            $action = function(){
                throw new \Fratily\Http\Message\Status\NotFound();
            };
        }

        return $handlerBuilder
            ->append(
                new Controller\ActionMiddleware($this->getContainer())
            )
            ->create(
                $kernel->getContainer()->has("kernel.responseFactory")
                    ? $kernel->getContainer()->get("kernel.responseFactory")
                    : new \Fratily\Http\Message\ResponseFactory()
            )
            ->handle(
                $request
                    ->withAttribute("action", $action)
                    ->withAttribute("routing", $routing)
                    ->withAttribute("kernel", $kernel)
                    ->withAttribute(
                        "environment",
                        $kernel->getConfig()->getEnvironment()
                    )
                    ->withAttribute(
                        "debug",
                        $kernel->getConfig()->isDebug()
                    )
            )
        ;
    }
921377
private function compareRequestParts(ServerRequestInterface $httpRequest, RequestConditions $expectedRequest)
    {
        $atLeastOneExecution = false;
        $requestParts = ['Method', 'Url', 'Body'];

        foreach ($requestParts as $requestPart) {
            $getter = "get{$requestPart}";
            $matcher = "request{$requestPart}MatchesExpectation";
            if ($expectedRequest->{$getter}()) {
                $this->logger->debug("Checking {$requestPart} against expectation");
                if (!$this->{$matcher}($httpRequest, $expectedRequest)) {
                    return null;
                }
                $atLeastOneExecution = true;
            }
        }

        return $atLeastOneExecution;
    }
1014203
public function dispatchRequest(ServerRequestInterface $request) : ResponseInterface
    {
        $match = $this->dispatch($request->getMethod(), $request->getUri()->getPath());

        switch ($match[0]) {
            case FastRoute::NOT_FOUND:
                $this->setNotFoundDecoratorMiddleware();
                break;
            case FastRoute::METHOD_NOT_ALLOWED:
                $allowed = (array) $match[1];
                $this->setMethodNotAllowedDecoratorMiddleware($allowed);
                break;
            case FastRoute::FOUND:
                $match[1]->setVars($match[2]);
                $this->setFoundMiddleware($match[1]);
                break;
        }

        return $this->handle($request);
    }
3784
public function request($serverRequest = null)
    {
        if ($serverRequest === null) {
            $serverRequest = $this->sapiServerRequest();
        }
        return $this->builder->request($serverRequest);
    }
1109249
public function edit(ServerRequestInterface $request)
    {
        if ($this->isReadOnly()) {
            return new NotFoundStatusResponse();
        }

        if ($this->active_object && $this->active_object->isLoaded()) {
            $authenticated_user = $this->getAuthenticatedUser($request);

            if ($this->shouldCheckPermissions() && !$this->canEdit($this->active_object, $authenticated_user)) {
                return new ForbiddenStatusResponse();
            }

            $request_body = $request->getParsedBody();

            if (empty($request_body)) {
                $request_body = [];
            }

            if ($this->requestBodyContainsProtectedFields($this->active_object, $request_body)) {
                return new BadRequestStatusResponse();
            }

            $this->cleanUpRequestBodyForEdit($request_body, $authenticated_user);

            try {
                return $this->pool->modify($this->active_object, $request_body);
            } catch (ValidationException $e) {
                return $e;
            }
        } else {
            return new NotFoundStatusResponse();
        }
    }
479261
public static function createFromServerRequest(ServerRequest $serverRequest)
    {
        return new Request(
            $serverRequest->getMethod(),
            $serverRequest->getUri(),
            $serverRequest->getHeaders(),
            $serverRequest->getBody(),
            $serverRequest->getProtocolVersion()
        );
    }
183851
public function request(ServerRequest $request = null)
    {
        $finding = $this->map->findByRequest($request = ($request ? : $this->request));

        return $this->run($finding);
    }
1252094
public function onRequest(ServerRequestInterface $request)
    {
        if ($this->isPopulateServer()) {
            $this->prepareEnvironment($request);
        }

        $remoteIp = $request->getHeaderLine('X-PHP-PM-Remote-IP');
        $remotePort = $request->getHeaderLine('X-PHP-PM-Remote-Port');

        $request = $request->withoutHeader('X-PHP-PM-Remote-IP');
        $request = $request->withoutHeader('X-PHP-PM-Remote-Port');

        $request = $request->withAttribute('remote_address', $remoteIp);
        $request = $request->withAttribute('remote_port', $remotePort);

        $logTime = date('d/M/Y:H:i:s O');

        $catchLog = function ($e) {
            console_log((string) $e);
            return new Response(500);
        };

        try {
            $response = $this->handleRequest($request);
        } catch (\Throwable $t) {
            $response = $catchLog($t);
        }

        $promise = new Promise(function ($resolve) use ($response) {
            return $resolve($response);
        });

        $promise = $promise->then(function (ResponseInterface $response) use ($request, $logTime, $remoteIp) {
            if ($this->isLogging()) {
                $this->logResponse($request, $response, $logTime, $remoteIp);
            }
            return $response;
        });

        return $promise;
    }
725107
private function buildSession(ServerRequestInterface $request)
    {
        $data = $this->handler->getCookie($request, $this->options['cookie_name']);

        $session = call_user_func([$this->options['session_class'], 'fromSerialized'], $data);
        if (!$session) {
            $session = new $this->options['session_class'];
        }

        return $session;
    }
1051653
private function getPsrRequest(Request $symfonyRequest): ServerRequestInterface
    {
        $psrRequest = $this->diactorosFactory->createRequest($symfonyRequest);
        $psrRequest = $psrRequest->withAttribute('request', $symfonyRequest);

        return $psrRequest;
    }