Documentation

HTTP

Namespaces

Auth

Interfaces, Classes and Traits

HttpException
An exception representing a HTTP error.
MessageInterface
The MessageInterface is the base interface that's used by both the RequestInterface and ResponseInterface.
RequestInterface
The RequestInterface represents a HTTP request.
ResponseInterface
This interface represents a HTTP response.
ResponseMock
HTTP Response Mock object.
SapiMock
HTTP Response Mock object.
Client
A rudimentary HTTP client.
ClientException
This exception may be emitted by the HTTP\Client class, in case there was a problem emitting the request.
ClientHttpException
This exception represents a HTTP error coming from the Client.
Message
This is the abstract base class for both the Request and Response objects.
Request
The Request class represents a single HTTP request.
RequestDecorator
Request Decorator.
Response
This class represents a single HTTP response.
ResponseDecorator
Response Decorator.
Sapi
PHP SAPI.
Version
This class contains the version number for the HTTP package.
ClientTest
ClientMock
A rudimentary HTTP client.
FunctionsTest
MessageDecoratorTest
MessageTest
MessageMock
This is the abstract base class for both the Request and Response objects.
NegotiateTest
RequestDecoratorTest
RequestTest
ResponseDecoratorTest
ResponseTest
SapiTest
URLUtilTest
MessageDecoratorTrait
This trait contains a bunch of methods, shared by both the RequestDecorator and the ResponseDecorator.

Table of Contents

parseDate()  : bool|DateTime
Parses a HTTP date-string.
toDate()  : string
Transforms a DateTime object to a valid HTTP/1.1 Date header value.
negotiateContentType()  : string|null
This function can be used to aid with content negotiation.
parsePrefer()  : array<string|int, mixed>
Parses the Prefer header, as defined in RFC7240.
getHeaderValues()  : array<string|int, mixed>
This method splits up headers into all their individual values.
parseMimeType()  : array<string|int, mixed>
Parses a mime-type and splits it into:.
encodePath()  : string
Encodes the path of a url.
encodePathSegment()  : string
Encodes a 1 segment of a path.
decodePath()  : string
Decodes a url-encoded path.
decodePathSegment()  : string
Decodes a url-encoded path segment.

Functions

parseDate()

Parses a HTTP date-string.

parseDate(string $dateString) : bool|DateTime

This method returns false if the date is invalid.

The following formats are supported: Sun, 06 Nov 1994 08:49:37 GMT ; IMF-fixdate Sunday, 06-Nov-94 08:49:37 GMT ; obsolete RFC 850 format Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format

See: http://tools.ietf.org/html/rfc7231#section-7.1.1.1

Parameters
$dateString : string
Return values
bool|DateTime

toDate()

Transforms a DateTime object to a valid HTTP/1.1 Date header value.

toDate(DateTime $dateTime) : string
Parameters
$dateTime : DateTime
Return values
string

negotiateContentType()

This function can be used to aid with content negotiation.

negotiateContentType(string|null $acceptHeaderValue, array<string|int, mixed> $availableOptions) : string|null

It takes 2 arguments, the $acceptHeaderValue, which usually comes from an Accept header, and $availableOptions, which contains an array of items that the server can support.

The result of this function will be the 'best possible option'. If no best possible option could be found, null is returned.

When it's null you can according to the spec either return a default, or you can choose to emit 406 Not Acceptable.

The method also accepts sending 'null' for the $acceptHeaderValue, implying that no accept header was sent.

Parameters
$acceptHeaderValue : string|null
$availableOptions : array<string|int, mixed>
Return values
string|null

parsePrefer()

Parses the Prefer header, as defined in RFC7240.

parsePrefer(string|array<string|int, string> $input) : array<string|int, mixed>

Input can be given as a single header value (string) or multiple headers (array of string).

This method will return a key->value array with the various Prefer parameters.

Prefer: return=minimal will result in:

[ 'return' => 'minimal' ]

Prefer: foo, wait=10 will result in:

[ 'foo' => true, 'wait' => '10']

This method also supports the formats from older drafts of RFC7240, and it will automatically map them to the new values, as the older values are still pretty common.

Parameters are currently discarded. There's no known prefer value that uses them.

Parameters
$input : string|array<string|int, string>
Return values
array<string|int, mixed>

getHeaderValues()

This method splits up headers into all their individual values.

getHeaderValues(string|array<string|int, string> $values[, string|array<string|int, string> $values2 = null ]) : array<string|int, mixed>

A HTTP header may have more than one header, such as this: Cache-Control: private, no-store

Header values are always split with a comma.

You can pass either a string, or an array. The resulting value is always an array with each spliced value.

If the second headers argument is set, this value will simply be merged in. This makes it quicker to merge an old list of values with a new set.

Parameters
$values : string|array<string|int, string>
$values2 : string|array<string|int, string> = null
Return values
array<string|int, mixed>

parseMimeType()

Parses a mime-type and splits it into:.

parseMimeType(string $str) : array<string|int, mixed>
  1. type
  2. subtype
  3. quality
  4. parameters
Parameters
$str : string
Return values
array<string|int, mixed>

encodePath()

Encodes the path of a url.

encodePath(string $path) : string

slashes (/) are treated as path-separators.

Parameters
$path : string
Return values
string

encodePathSegment()

Encodes a 1 segment of a path.

encodePathSegment(string $pathSegment) : string

Slashes are considered part of the name, and are encoded as %2f

Parameters
$pathSegment : string
Return values
string

decodePath()

Decodes a url-encoded path.

decodePath(string $path) : string
Parameters
$path : string
Return values
string

decodePathSegment()

Decodes a url-encoded path segment.

decodePathSegment(string $path) : string
Parameters
$path : string
Return values
string

Search results