com\setasign\SetaFramework\Http

HttpFactory Class HttpFactory

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

Class hierarchy

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
  • HttpFactoryInterface

Summary

Properties

$requestFactory

$requestPathPrefix

$responseFactory

$serverRequestFactory

$streamFactory

$uploadFileFactory

$uriFactory


Methods

__construct()

public HttpFactory::__construct (
\Psr\Http\Message\RequestFactoryInterface $requestFactory,
\Psr\Http\Message\ResponseFactoryInterface $responseFactory,
\Psr\Http\Message\ServerRequestFactoryInterface $serverRequestFactory,
\Psr\Http\Message\StreamFactoryInterface $streamFactory,
\Psr\Http\Message\UploadedFileFactoryInterface $uploadFileFactory,
\Psr\Http\Message\UriFactoryInterface $uriFactory,
\com\setasign\SetaFramework\Bootstrap\RequestPathPrefix $requestPathPrefix
)
Parameters
$requestFactory : \Psr\Http\Message\RequestFactoryInterface
 
$responseFactory : \Psr\Http\Message\ResponseFactoryInterface
 
$serverRequestFactory : \Psr\Http\Message\ServerRequestFactoryInterface
 
$streamFactory : \Psr\Http\Message\StreamFactoryInterface
 
$uploadFileFactory : \Psr\Http\Message\UploadedFileFactoryInterface
 
$uriFactory : \Psr\Http\Message\UriFactoryInterface
 
$requestPathPrefix : \com\setasign\SetaFramework\Bootstrap\RequestPathPrefix
 

createHtmlResponse()

public HttpFactory::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()

public HttpFactory::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()

public HttpFactory::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()

public HttpFactory::createRequest (
string $method,
\Psr\Http\Message\UriInterface|string $uri
): \Psr\Http\Message\RequestInterface
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()

public HttpFactory::createResponse (
int $code = 200,
string $reasonPhrase = ''
): \Psr\Http\Message\ResponseInterface
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()

public HttpFactory::createServerRequest (
string $method,
\Psr\Http\Message\UriInterface|string $uri,
array $serverParams = array ( )
): \Psr\Http\Message\ServerRequestInterface
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()

public HttpFactory::createStream (
string $content = ''
): \Psr\Http\Message\StreamInterface
Parameters
$content : string

String content with which to populate the stream.

createStreamFromFile()

public HttpFactory::createStreamFromFile (
string $filename,
string $mode = 'r'
): \Psr\Http\Message\StreamInterface
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()

public HttpFactory::createStreamFromResource (
resource $resource
): \Psr\Http\Message\StreamInterface
Parameters
$resource : resource

PHP resource to use as basis of stream.

createUploadedFile()

public HttpFactory::createUploadedFile (
\Psr\Http\Message\StreamInterface $stream,
?int $size = null,
int $error = \UPLOAD_ERR_OK,
?string $clientFilename = null,
?string $clientMediaType = null
): \Psr\Http\Message\UploadedFileInterface
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.

createUri()

public HttpFactory::createUri (
string $uri = ''
): \Psr\Http\Message\UriInterface
Parameters
$uri : string
 
Exceptions

Throws \InvalidArgumentException If the given URI cannot be parsed.