Kotchasan

AbstractRequest extends AbstractMessage
in package
implements RequestInterface

Class for managing URLs

Tags
see
https://www.kotchasan.com/

Interfaces, Classes and Traits

RequestInterface
Representation of an outgoing, client-side request.

Table of Contents

$headers  : array<string|int, mixed>
$method  : string|null
$protocol  : string
$requestTarget  : string|null
$stream  : StreamInterface
$uri  : Uri|null
__construct()  : mixed
Initializes the class.
createUriWithGet()  : Uri
Create a class from a link and merge values from $_GET
createUriWithGlobals()  : Uri
Create a class from a link and merge values from $_GET and $_POST
createUriWithPost()  : Uri
Create a class from a link and merge values from $_POST
getBody()  : StreamInterface
Get the body of the message.
getHeader()  : array<string|int, string>
Get the specified header as an array.
getHeaderLine()  : string
Get the specified header as a string.
getHeaders()  : array<string|int, mixed>
Get all the headers.
getMethod()  : string
Get the HTTP method
getProtocolVersion()  : string
Get the protocol version of the message.
getRequestTarget()  : string
Get the request target
getUri()  : Uri
Get the URI
hasHeader()  : bool
Check if a header exists.
map()  : mixed
Merge arrays $_GET and $_POST into a single data array
withAddedHeader()  : static
Add a new header.
withBody()  : static
Set the message body.
withHeader()  : static
Set a header, replacing any existing values.
withHeaders()  : static
Set multiple headers, replacing any existing values.
withMethod()  : static
Set the HTTP method
withoutHeader()  : static
Remove a header.
withProtocolVersion()  : static
Set the protocol version of the message.
withRequestTarget()  : static
Set the request target
withUri()  : static
Set the URI
filterHeader()  : mixed
Check the validity of a header.
getRequestHeaders()  : array<string|int, mixed>
Function to retrieve HTTP headers.

Properties

$headers

protected array<string|int, mixed> $headers = []

The headers of the message.

$protocol

protected string $protocol = '1.1'

The protocol version of the message.

$requestTarget

protected string|null $requestTarget

The request target

Methods

__construct()

Initializes the class.

public __construct([bool $withHeader = false ]) : mixed
Parameters
$withHeader : bool = false

Whether to include the HTTP header or not. Default is false.

Return values
mixed

createUriWithGet()

Create a class from a link and merge values from $_GET

public static createUriWithGet([string $uri = 'index.php' ][, array<string|int, mixed> $exclude = [] ]) : Uri
Parameters
$uri : string = 'index.php'

The URI, default is 'index.php'

$exclude : array<string|int, mixed> = []

An array of keys from $_GET to exclude from the URL

Return values
Uri

createUriWithGlobals()

Create a class from a link and merge values from $_GET and $_POST

public createUriWithGlobals([string $uri = 'index.php' ][, array<string|int, mixed> $exclude = [] ]) : Uri
Parameters
$uri : string = 'index.php'

The URI, default is 'index.php'

$exclude : array<string|int, mixed> = []

An array of keys from $_GET and $_POST to exclude from the URL

Return values
Uri

createUriWithPost()

Create a class from a link and merge values from $_POST

public static createUriWithPost([string $uri = 'index.php' ][, array<string|int, mixed> $exclude = [] ]) : Uri
Parameters
$uri : string = 'index.php'

The URI, default is 'index.php'

$exclude : array<string|int, mixed> = []

An array of keys from $_POST to exclude from the URL

Return values
Uri

getHeader()

Get the specified header as an array.

public getHeader(string $name) : array<string|int, string>
Parameters
$name : string

The name of the header.

Return values
array<string|int, string>

The values of the header as an array, or an empty array if not found.

getHeaderLine()

Get the specified header as a string.

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

The name of the header.

Return values
string

The concatenated values of the header, separated by commas, or an empty string if not found.

getHeaders()

Get all the headers.

public getHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>

The headers of the message.

getMethod()

Get the HTTP method

public getMethod() : string
Return values
string

The request method

getProtocolVersion()

Get the protocol version of the message.

public getProtocolVersion() : string
Return values
string

The protocol version.

getRequestTarget()

Get the request target

public getRequestTarget() : string
Return values
string

The request target

hasHeader()

Check if a header exists.

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

The name of the header.

Return values
bool

True if the header exists, false otherwise.

map()

Merge arrays $_GET and $_POST into a single data array

public static map(array<string|int, mixed> &$result, array<string|int, mixed> $array[, array<string|int, mixed> $exclude = [] ]) : mixed
Parameters
$result : array<string|int, mixed>

A variable to store the result for further use

$array : array<string|int, mixed>

The array to merge, e.g., $_GET or $_POST

$exclude : array<string|int, mixed> = []

A list of keys from the array that should not be included in the result

Return values
mixed

withAddedHeader()

Add a new header.

public withAddedHeader(string $name, string|array<string|int, string> $value) : static
Parameters
$name : string

The name of the header.

$value : string|array<string|int, string>

The value(s) of the header as a string or an array of strings.

Tags
throws
InvalidArgumentException

If the header name is invalid.

Return values
static

withHeader()

Set a header, replacing any existing values.

public withHeader(string $name, string|array<string|int, string> $value) : static
Parameters
$name : string

The name of the header.

$value : string|array<string|int, string>

The value(s) of the header as a string or an array of strings.

Tags
throws
InvalidArgumentException

for invalid header names or values.

Return values
static

withHeaders()

Set multiple headers, replacing any existing values.

public withHeaders(array<string|int, mixed> $headers) : static
Parameters
$headers : array<string|int, mixed>

An array of headers in the format: array($key => $value, $key => $value...)

Tags
throws
InvalidArgumentException

for invalid header names or values.

Return values
static

withMethod()

Set the HTTP method

public withMethod(string $method) : static
Parameters
$method : string

The HTTP method

Return values
static

withoutHeader()

Remove a header.

public withoutHeader(string $name) : static
Parameters
$name : string

The name of the header to remove.

Return values
static

withProtocolVersion()

Set the protocol version of the message.

public withProtocolVersion(string $version) : static
Parameters
$version : string

The protocol version (e.g., 1.1, 1.0).

Return values
static

withRequestTarget()

Set the request target

public withRequestTarget(mixed $requestTarget) : static
Parameters
$requestTarget : mixed

The request target

Return values
static

withUri()

Set the URI

public withUri(UriInterface $uri[, bool $preserveHost = false ]) : static
Parameters
$uri : UriInterface

The URI

$preserveHost : bool = false

Whether to preserve the host header

Return values
static

filterHeader()

Check the validity of a header.

protected filterHeader(string $name) : mixed
Parameters
$name : string

The name of the header.

Tags
throws
InvalidArgumentException

If the header is invalid.

Return values
mixed

getRequestHeaders()

Function to retrieve HTTP headers.

protected getRequestHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>

An array of HTTP headers.

Search results