com\setasign\SetaFramework\Http

HttpFactoryInterface Interface HttpFactoryInterface

File: /SetaFramework/src/Http/HttpFactoryInterface.php

Implemented in

Implements

  • \Psr\Http\Message\RequestFactoryInterface
  • \Psr\Http\Message\ResponseFactoryInterface
  • \Psr\Http\Message\ServerRequestFactoryInterface
  • \Psr\Http\Message\StreamFactoryInterface
  • \Psr\Http\Message\UploadedFileFactoryInterface
  • \Psr\Http\Message\UriFactoryInterface

Summary

Methods

createHtmlResponse()

abstract public HttpFactoryInterface::createHtmlResponse (
string|\Psr\Http\Message\StreamInterface $html,
int $status = 200,
array $headers = array ( )
): \Psr\Http\Message\ResponseInterface
Parameters
$html : string|\Psr\Http\Message\StreamInterface

HTML or stream for the message body.

$status : int

Integer status code for the response; 200 by default.

$headers : array

Array of headers to use at initialization.

createJsonResponse()

abstract public HttpFactoryInterface::createJsonResponse (
mixed $data,
int $status = 200,
array $headers = array ( ),
int $encodingOptions = 79
): \Psr\Http\Message\ResponseInterface

Create a JSON response with the given data.

Default JSON encoding is performed with the following options, which produces RFC4627-compliant JSON, capable of embedding into HTML.

  • JSON_HEX_TAG
  • JSON_HEX_APOS
  • JSON_HEX_AMP
  • JSON_HEX_QUOT
  • JSON_UNESCAPED_SLASHES
Parameters
$data : mixed

Data to convert to JSON.

$status : int

Integer status code for the response; 200 by default.

$headers : array

Array of headers to use at initialization.

$encodingOptions : int

JSON encoding options to use.

Exceptions

Throws \JsonException

createRedirectResponse()

abstract public HttpFactoryInterface::createRedirectResponse (
string|\Psr\Http\Message\UriInterface $uri,
bool $isExternal = false,
int $status = 302,
array $headers = array ( )
): \Psr\Http\Message\ResponseInterface
Parameters
$uri : string|\Psr\Http\Message\UriInterface
 
$isExternal : bool

If false the url will be prepended with the requestPathPrefix.

$status : int
 
$headers : array
 

createRequest()

abstract public \Psr\Http\Message\RequestFactoryInterface::createRequest (
string $method,
\Psr\Http\Message\UriInterface|string $uri
): \Psr\Http\Message\RequestInterface

Create a new request.

Parameters
$method : string

The HTTP method associated with the request.

$uri : \Psr\Http\Message\UriInterface|string

The URI associated with the request. If the value is a string, the factory MUST create a UriInterface instance based on it.

createResponse()

abstract public \Psr\Http\Message\ResponseFactoryInterface::createResponse (
int $code = 200,
string $reasonPhrase = ''
): \Psr\Http\Message\ResponseInterface

Create a new response.

Parameters
$code : int

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.

createServerRequest()

abstract public \Psr\Http\Message\ServerRequestFactoryInterface::createServerRequest (
string $method,
\Psr\Http\Message\UriInterface|string $uri,
array $serverParams = array ( )
): \Psr\Http\Message\ServerRequestInterface

Create a new server request.

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 : \Psr\Http\Message\UriInterface|string

The URI associated with the request. If the value is a string, the factory MUST create a UriInterface instance based on it.

$serverParams : array

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

createStream()

abstract public \Psr\Http\Message\StreamFactoryInterface::createStream (
string $content = ''
): \Psr\Http\Message\StreamInterface

Create a new stream from a string.

The stream SHOULD be created with a temporary resource.

Parameters
$content : string

String content with which to populate the stream.

createStreamFromFile()

abstract public \Psr\Http\Message\StreamFactoryInterface::createStreamFromFile (
string $filename,
string $mode = 'r'
): \Psr\Http\Message\StreamInterface

Create a stream from an existing file.

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

Mode with which to open the underlying filename/stream.

Exceptions

Throws \RuntimeException If the file cannot be opened.

Throws \InvalidArgumentException If the mode is invalid.

createStreamFromResource()

abstract public \Psr\Http\Message\StreamFactoryInterface::createStreamFromResource (
resource $resource
): \Psr\Http\Message\StreamInterface

Create a new stream from an existing resource.

The stream MUST be readable and may be writable.

Parameters
$resource : resource

PHP resource to use as basis of stream.

createUploadedFile()

abstract public \Psr\Http\Message\UploadedFileFactoryInterface::createUploadedFile (
\Psr\Http\Message\StreamInterface $stream,
?int $size = null,
int $error = \UPLOAD_ERR_OK,
?string $clientFilename = null,
?string $clientMediaType = null
): \Psr\Http\Message\UploadedFileInterface

Create a new uploaded file.

If a size is not provided it will be determined by checking the size of the file.

Parameters
$stream : \Psr\Http\Message\StreamInterface

Underlying stream representing the uploaded file content.

$size : ?int

in bytes

$error : int

PHP file upload error

$clientFilename : ?string

Filename as provided by the client, if any.

$clientMediaType : ?string

Media type as provided by the client, if any.

Exceptions

Throws \InvalidArgumentException If the file resource is not readable.

See

createUri()

abstract public \Psr\Http\Message\UriFactoryInterface::createUri (
string $uri = ''
): \Psr\Http\Message\UriInterface

Create a new URI.

Parameters
$uri : string
 
Exceptions

Throws \InvalidArgumentException If the given URI cannot be parsed.