HttpFactory
in package
implements
RequestFactoryInterface, ResponseFactoryInterface, ServerRequestFactoryInterface, StreamFactoryInterface, UploadedFileFactoryInterface, UriFactoryInterface
Implements all of the PSR-17 interfaces.
Note: in consuming code it is recommended to require the implemented interfaces and inject the instance of this class multiple times.
Table of Contents
Interfaces
- RequestFactoryInterface
- ResponseFactoryInterface
- ServerRequestFactoryInterface
- StreamFactoryInterface
- UploadedFileFactoryInterface
- UriFactoryInterface
Methods
- createRequest() : RequestInterface
- Create a new request.
- createResponse() : ResponseInterface
- Create a new response.
- createServerRequest() : ServerRequestInterface
- Create a new server request.
- createStream() : StreamInterface
- Create a new stream from a string.
- createStreamFromFile() : StreamInterface
- Create a stream from an existing file.
- createStreamFromResource() : StreamInterface
- Create a new stream from an existing resource.
- createUploadedFile() : UploadedFileInterface
- Create a new uploaded file.
- createUri() : UriInterface
- Create a new URI.
Methods
createRequest()
Create a new request.
public
createRequest(string $method, mixed $uri) : RequestInterface
Parameters
- $method : string
-
The HTTP method associated with the request.
- $uri : mixed
-
The URI associated with the request. If the value is a string, the factory MUST create a UriInterface instance based on it.
Return values
RequestInterfacecreateResponse()
Create a new response.
public
createResponse([int $code = 200 ][, string $reasonPhrase = '' ]) : ResponseInterface
Parameters
- $code : int = 200
-
HTTP status code; defaults to 200
- $reasonPhrase : string = ''
-
Reason phrase to associate with status code in generated response; if none is provided implementations MAY use the defaults as suggested in the HTTP specification.
Return values
ResponseInterfacecreateServerRequest()
Create a new server request.
public
createServerRequest(string $method, mixed $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 : mixed
-
The URI associated with the request. If the value is a string, the factory MUST create a UriInterface instance based on it.
- $serverParams : array<string|int, mixed> = []
-
Array of SAPI parameters with which to seed the generated request instance.
Return values
ServerRequestInterfacecreateStream()
Create a new stream from a string.
public
createStream([string $content = '' ]) : StreamInterface
The stream SHOULD be created with a temporary resource.
Parameters
- $content : string = ''
-
String content with which to populate the stream.
Return values
StreamInterfacecreateStreamFromFile()
Create a stream from an existing file.
public
createStreamFromFile(string $file[, string $mode = 'r' ]) : StreamInterface
The file MUST be opened using the given mode, which may be any mode
supported by the fopen
function.
The $filename
MAY be any string supported by fopen()
.
Parameters
- $file : string
- $mode : string = 'r'
-
Mode with which to open the underlying filename/stream.
Return values
StreamInterfacecreateStreamFromResource()
Create a new stream from an existing resource.
public
createStreamFromResource(mixed $resource) : StreamInterface
The stream MUST be readable and may be writable.
Parameters
- $resource : mixed
-
PHP resource to use as basis of stream.
Return values
StreamInterfacecreateUploadedFile()
Create a new uploaded file.
public
createUploadedFile(StreamInterface $stream[, int|null $size = null ][, int $error = UPLOAD_ERR_OK ][, string|null $clientFilename = null ][, string|null $clientMediaType = null ]) : UploadedFileInterface
If a size is not provided it will be determined by checking the size of the file.
Parameters
- $stream : StreamInterface
-
Underlying stream representing the uploaded file content.
- $size : int|null = null
-
in bytes
- $error : int = UPLOAD_ERR_OK
-
PHP file upload error
- $clientFilename : string|null = null
-
Filename as provided by the client, if any.
- $clientMediaType : string|null = null
-
Media type as provided by the client, if any.
Return values
UploadedFileInterfacecreateUri()
Create a new URI.
public
createUri([string $uri = '' ]) : UriInterface
Parameters
- $uri : string = ''