com\setasign\SetaFramework\Request

ServerRequest Class Request

File: /SetaFramework/src/Request/ServerRequest.php

A wrapper for the psr request.

Class hierarchy

Implements

  • \Psr\Http\Message\MessageInterface
  • \Psr\Http\Message\RequestInterface
  • \Psr\Http\Message\ServerRequestInterface

Summary

Properties

$request

protected \Psr\Http\Message\ServerRequestInterface ServerRequest::$request

$trustAny

protected ServerRequest::$trustAny = false

$trustedProxies

protected ServerRequest::$trustedProxies = array()

$trustedProxiesIpHeader


Methods

__construct()

public ServerRequest::__construct (
\Psr\Http\Message\ServerRequestInterface $request
)

Request constructor.

Parameters
$request : \Psr\Http\Message\ServerRequestInterface
 

doesAccept()

public ServerRequest::doesAccept (
$contentType
): bool

Checks the accept-header whether $contentType is included.

If the request doesn't have an accept-header every contentType will return true!

Parameters
$contentType
 

getAttribute()

public ServerRequest::getAttribute (
string $name,
mixed $default = null
): mixed

Retrieve a single derived request attribute.

Parameters
$name : string

The attribute name.

$default : mixed

Default value to return if the attribute does not exist.

See
  • \Psr\Http\Message\ServerRequestInterface::getAttributes()

getAttributes()

public ServerRequest::getAttributes (
void
): array

Retrieve attributes derived from the request.

Return Values

Attributes derived from the request.

getBody()

public ServerRequest::getBody (
void
): \Psr\Http\Message\StreamInterface

Gets the body of the message.

Return Values

Returns the body as a stream.

getCookieParams()

public ServerRequest::getCookieParams (
void
): array

Retrieve cookies.

getGet()

public ServerRequest::getGet (
string $key,
mixed $default = null
): ?mixed
Parameters
$key : string
 
$default : mixed
 

getGetArray()

public ServerRequest::getGetArray (
void
): array

getHeader()

public ServerRequest::getHeader (
string $name
): array

Retrieves a message header value by the given case-insensitive name.

Parameters
$name : string

Case-insensitive header field name.

Return Values

An array of string values as provided for the given header. If the header does not appear in the message, this method MUST return an empty array.

getHeaderLine()

public ServerRequest::getHeaderLine (
string $name
): string

Retrieves a comma-separated string of the values for a single header.

Parameters
$name : string

Case-insensitive header field name.

Return Values

A string of values as provided for the given header concatenated together using a comma. If the header does not appear in the message, this method MUST return an empty string.

getHeaders()

public ServerRequest::getHeaders (
void
): array

Retrieves all message header values.

Return Values

Returns an associative array of the message's headers. Each key MUST be a header name, and each value MUST be an array of strings for that header.

getJson()

public ServerRequest::getJson (
string $key,
mixed $default = null
): ?mixed

Gets the content of the incoming json data.

Parameters
$key : string
 
$default : mixed
 
Exceptions

Throws \BadMethodCallException

See

getJsonArray()

public ServerRequest::getJsonArray (
void
): array

getMethod()

public ServerRequest::getMethod (
void
): string

Retrieves the HTTP method of the request.

Return Values

Returns the request method.

getParsedBody()

public ServerRequest::getParsedBody (
void
): null|array|object

Retrieve any parameters provided in the request body.

Return Values

The deserialized body parameters, if any. These will typically be an array or object.

getPost()

public ServerRequest::getPost (
string $key,
?mixed $default = null
): ?mixed
Parameters
$key : string
 
$default : ?mixed
 

getPostArray()

public ServerRequest::getPostArray (
void
): array

getProtocolVersion()

public ServerRequest::getProtocolVersion (
void
): string

Retrieves the HTTP protocol version as a string.

Return Values

HTTP protocol version.

getQueryParams()

public ServerRequest::getQueryParams (
void
): array

Retrieve query string arguments.

getRemoteAddress()

public ServerRequest::getRemoteAddress (
void
): string

getRequest()

public ServerRequest::getRequest (
void
): \Psr\Http\Message\ServerRequestInterface

getRequestTarget()

public ServerRequest::getRequestTarget (
void
): string

Retrieves the message's request target.

getServerParams()

public ServerRequest::getServerParams (
void
): array

Retrieve server parameters.

getUploadedFiles()

public ServerRequest::getUploadedFiles (
void
): array

Retrieve normalized file upload data.

Return Values

An array tree of UploadedFileInterface instances; an empty array MUST be returned if no data is present.

getUri()

public ServerRequest::getUri (
void
): \Psr\Http\Message\UriInterface

Retrieves the URI instance.

Return Values

Returns a UriInterface instance representing the URI of the request.

hasHeader()

public ServerRequest::hasHeader (
string $name
): bool

Checks if a header exists by the given case-insensitive name.

Parameters
$name : string

Case-insensitive header field name.

Return Values

Returns true if any header names match the given header name using a case-insensitive string comparison. Returns false if no matching header name is found in the message.

isFromTrustedProxy()

protected ServerRequest::isFromTrustedProxy (
string $ip
): bool

Indicates whether this request is from a trusted proxy.

Parameters
$ip : string
 

isJson()

public ServerRequest::isJson (
void
): bool

isPost()

public ServerRequest::isPost (
void
): bool

withAddedHeader()

public ServerRequest::withAddedHeader (
string $name,
string|string[] $value
): \Psr\Http\Message\MessageInterface

Return an instance with the specified header appended with the given value.

Parameters
$name : string

Case-insensitive header field name to add.

$value : string|string[]

Header value(s).

Exceptions

Throws \InvalidArgumentException for invalid header names or values.

withAttribute()

public ServerRequest::withAttribute (
string $name,
mixed $value
): \Psr\Http\Message\ServerRequestInterface

Return an instance with the specified derived request attribute.

Parameters
$name : string

The attribute name.

$value : mixed

The value of the attribute.

See
  • \Psr\Http\Message\ServerRequestInterface::getAttributes()

withBody()

public ServerRequest::withBody (
\Psr\Http\Message\StreamInterface $body
): \Psr\Http\Message\MessageInterface

Return an instance with the specified message body.

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

Body.

Exceptions

Throws \InvalidArgumentException When the body is not valid.

withCookieParams()

public ServerRequest::withCookieParams (
array $cookies
): \Psr\Http\Message\ServerRequestInterface

Return an instance with the specified cookies.

Parameters
$cookies : array

Array of key/value pairs representing cookies.

withHeader()

public ServerRequest::withHeader (
string $name,
string|string[] $value
): \Psr\Http\Message\MessageInterface

Return an instance with the provided value replacing the specified header.

Parameters
$name : string

Case-insensitive header field name.

$value : string|string[]

Header value(s).

Exceptions

Throws \InvalidArgumentException for invalid header names or values.

withMethod()

public ServerRequest::withMethod (
string $method
): \Psr\Http\Message\ServerRequestInterface

Return an instance with the provided HTTP method.

Parameters
$method : string

Case-sensitive method.

Exceptions

Throws \InvalidArgumentException for invalid HTTP methods.

withParsedBody()

public ServerRequest::withParsedBody (
null|array|object $data
): \Psr\Http\Message\ServerRequestInterface

Return an instance with the specified body parameters.

Parameters
$data : null|array|object

The deserialized body data. This will typically be in an array or object.

Exceptions

Throws \InvalidArgumentException if an unsupported argument type is provided.

withProtocolVersion()

public ServerRequest::withProtocolVersion (
string $version
): \Psr\Http\Message\MessageInterface

Return an instance with the specified HTTP protocol version.

Parameters
$version : string

HTTP protocol version

withQueryParams()

public ServerRequest::withQueryParams (
array $query
): \Psr\Http\Message\ServerRequestInterface

Return an instance with the specified query string arguments.

Parameters
$query : array

Array of query string arguments, typically from $_GET.

withRequestTarget()

public ServerRequest::withRequestTarget (
string $requestTarget
): \Psr\Http\Message\ServerRequestInterface

Return an instance with the specific request-target.

Parameters
$requestTarget : string
 

withUploadedFiles()

public ServerRequest::withUploadedFiles (
array $uploadedFiles
): \Psr\Http\Message\ServerRequestInterface

Create a new instance with the specified uploaded files.

Parameters
$uploadedFiles : array

An array tree of UploadedFileInterface instances.

Exceptions

Throws \InvalidArgumentException if an invalid structure is provided.

withUri()

public ServerRequest::withUri (
\Psr\Http\Message\UriInterface $uri,
bool $preserveHost = false
): \Psr\Http\Message\ServerRequestInterface

Returns an instance with the provided URI.

Parameters
$uri : \Psr\Http\Message\UriInterface

New request URI to use.

$preserveHost : bool

Preserve the original state of the Host header.

withoutAttribute()

public ServerRequest::withoutAttribute (
string $name
): \Psr\Http\Message\ServerRequestInterface

Return an instance that removes the specified derived request attribute.

Parameters
$name : string

The attribute name.

See
  • \Psr\Http\Message\ServerRequestInterface::getAttributes()

withoutHeader()

public ServerRequest::withoutHeader (
string $name
): \Psr\Http\Message\MessageInterface

Return an instance without the specified header.

Parameters
$name : string

Case-insensitive header field name to remove.