getServerParams example

if (isset($changes['query'])) {
            $uri = $uri->withQuery($changes['query']);
        }

        if ($request instanceof ServerRequestInterface) {
            $new = (new ServerRequest(
                $changes['method'] ?? $request->getMethod(),
                $uri,
                $headers,
                $changes['body'] ?? $request->getBody(),
                $changes['version'] ?? $request->getProtocolVersion(),
                $request->getServerParams()
            ))
            ->withParsedBody($request->getParsedBody())
            ->withQueryParams($request->getQueryParams())
            ->withCookieParams($request->getCookieParams())
            ->withUploadedFiles($request->getUploadedFiles());

            foreach ($request->getAttributes() as $key => $value) {
                $new = $new->withAttribute($key$value);
            }

            return $new;
        }
if ('' !== $server['QUERY_STRING']) {
                $server['REQUEST_URI'] .= '?'.$server['QUERY_STRING'];
            }

            if ('https' === $uri->getScheme()) {
                $server['HTTPS'] = 'on';
            }
        }

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

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

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

        $request = new Request(
            $psrRequest->getQueryParams(),
            $parsedBody,
            $psrRequest->getAttributes(),
            $psrRequest->getCookieParams(),
            $this->getFiles($psrRequest->getUploadedFiles()),
            $server,
            
$uploadedFiles = $psrRequest->getUploadedFiles();
        $this->assertSame('F1', $uploadedFiles['f1']->getStream()->__toString());
        $this->assertSame('f1.txt', $uploadedFiles['f1']->getClientFilename());
        $this->assertSame('text/plain', $uploadedFiles['f1']->getClientMediaType());
        $this->assertSame(\UPLOAD_ERR_OK, $uploadedFiles['f1']->getError());

        $this->assertSame('F2', $uploadedFiles['foo']['f2']->getStream()->__toString());
        $this->assertSame('f2.txt', $uploadedFiles['foo']['f2']->getClientFilename());
        $this->assertSame('text/plain', $uploadedFiles['foo']['f2']->getClientMediaType());
        $this->assertSame(\UPLOAD_ERR_OK, $uploadedFiles['foo']['f2']->getError());

        $serverParams = $psrRequest->getServerParams();
        $this->assertSame('POST', $serverParams['REQUEST_METHOD']);
        $this->assertSame('2.8', $serverParams['HTTP_X_SYMFONY']);
        $this->assertSame('POST', $psrRequest->getMethod());
        $this->assertSame(['2.8']$psrRequest->getHeader('X-Symfony'));
    }

    public function testGetContentCanBeCalledAfterRequestCreation()
    {
        $header = ['HTTP_HOST' => 'dunglas.fr'];
        $request = new Request([][][][][]$header, 'Content');

        
if ('' !== $server['QUERY_STRING']) {
                $server['REQUEST_URI'] .= '?'.$server['QUERY_STRING'];
            }

            if ('https' === $uri->getScheme()) {
                $server['HTTPS'] = 'on';
            }
        }

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

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

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

        $request = new Request(
            $psrRequest->getQueryParams(),
            $parsedBody,
            $psrRequest->getAttributes(),
            $psrRequest->getCookieParams(),
            $this->getFiles($psrRequest->getUploadedFiles()),
            $server,
            
Home | Imprint | This part of the site doesn't use cookies.