Documentation

Psr17Factory
in package
implements RequestFactoryInterface, ResponseFactoryInterface, ServerRequestFactoryInterface, StreamFactoryInterface, UploadedFileFactoryInterface, UriFactoryInterface

Tags
author

Tobias Nyholm tobias.nyholm@gmail.com

author

Martijn van der Ven martijn@vanderven.se

final

This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md

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
RequestInterface

createResponse()

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
ResponseInterface

createServerRequest()

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
ServerRequestInterface

createStream()

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
StreamInterface

createStreamFromFile()

Create a stream from an existing file.

public createStreamFromFile(string $filename[, 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
$filename : string

Filename or stream URI to use as basis of stream.

$mode : string = 'r'

Mode with which to open the underlying filename/stream.

Return values
StreamInterface

createStreamFromResource()

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
StreamInterface

createUploadedFile()

Create a new uploaded file.

public createUploadedFile(StreamInterface $stream[, int $size = null ][, int $error = UPLOAD_ERR_OK ][, string $clientFilename = null ][, string $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

in bytes

$error : int = UPLOAD_ERR_OK

PHP file upload error

$clientFilename : string = null

Filename as provided by the client, if any.

$clientMediaType : string = null

Media type as provided by the client, if any.

Return values
UploadedFileInterface

        
On this page

Search results