ServerRequestFactory implements ServerRequestFactoryInterface

Class to create ServerRequest objects

Highly inspired by https://github.com/phly/http/

Internal

Note that this is not public API yet.

Attributes
#[AsAlias]
\Psr\Http\Message\ServerRequestFactoryInterface::class
$public: true

Table of Contents

Interfaces

ServerRequestFactoryInterface

Methods

createServerRequest()  : ServerRequestInterface
Create a new server request.
fromGlobals()  : ServerRequest
Create a request from the original superglobal variables.
createUploadedFile()  : array<string|int, UploadedFileInterface>|UploadedFileInterface|null
Create and return an UploadedFile instance from a $_FILES specification.
normalizeUploadedFiles()  : array<string|int, mixed>
Normalize uploaded files
prepareHeaders()  : array<string|int, mixed>
Fetch headers from $_SERVER variables which are only the ones starting with HTTP_* and CONTENT_*

Methods

createServerRequest()

Create a new server request.

public createServerRequest(string $method, UriInterface|string $uri[, array<string|int, mixed> $serverParams = [] ]) : ServerRequestInterface

Note that server-params are taken precisely as given - no parsing/processing of the given values is performed, and, in particular, no attempt is made to determine the HTTP method or URI, which must be provided explicitly.

Parameters
$method : string

The HTTP method associated with the request.

$uri : UriInterface|string

The URI associated with the request.

$serverParams : array<string|int, mixed> = []

Array of SAPI parameters with which to seed the generated request instance.

Return values
ServerRequestInterface

fromGlobals()

Create a request from the original superglobal variables.

public static fromGlobals() : ServerRequest
Internal

Note that this is not public API yet.

Tags
throws
InvalidArgumentException

when invalid file values given

Return values
ServerRequest

createUploadedFile()

Create and return an UploadedFile instance from a $_FILES specification.

protected static createUploadedFile(array<string|int, mixed> $value) : array<string|int, UploadedFileInterface>|UploadedFileInterface|null

If the specification represents an array of values, this method will recursively resolve uploaded files.

Parameters
$value : array<string|int, mixed>

$_FILES structure

Return values
array<string|int, UploadedFileInterface>|UploadedFileInterface|null

normalizeUploadedFiles()

Normalize uploaded files

protected static normalizeUploadedFiles(array<string|int, mixed> $files) : array<string|int, mixed>

Transforms each value into an UploadedFileInterface instance, and ensures that nested arrays are normalized.

Parameters
$files : array<string|int, mixed>
Tags
throws
InvalidArgumentException

for unrecognized values

Return values
array<string|int, mixed>

prepareHeaders()

Fetch headers from $_SERVER variables which are only the ones starting with HTTP_* and CONTENT_*

protected static prepareHeaders(array<string|int, mixed> $server) : array<string|int, mixed>
Parameters
$server : array<string|int, mixed>
Return values
array<string|int, mixed>

        
On this page

Search results