Class Headers
HTTP Header field definitions.
Instances of this class are used to collect and manipulate HTTP header field definitions.
Header field instances are used to handle the definition of complex header fields such as
Content-Type
and Cache-Control
. For instance a ICanBoogie\HTTP\Headers\CacheControl
instance
is used to handle the directives of the Cache-Control
header field.
-
ICanBoogie\HTTP\Headers
implements
ArrayAccess,
IteratorAggregate
Namespace: ICanBoogie\
HTTP
See:
http://tools.ietf.org/html/rfc2616#section-14
Located at Headers.php
Methods summary
public
__construct( array $fields
= [] )
If the REQUEST_URI
key is found in the header fields they are considered coming from the
super global $_SERVER
array in which case they are filtered to keep only keys
starting with the HTTP_
prefix. Also, header field names are normalized. For instance,
HTTP_CONTENT_TYPE
becomes Content-Type
.
If the REQUEST_URI
key is found in the header fields they are considered coming from the
super global $_SERVER
array in which case they are filtered to keep only keys
starting with the HTTP_
prefix. Also, header field names are normalized. For instance,
HTTP_CONTENT_TYPE
becomes Content-Type
.
Parameters
$fields
- The initial headers.
public
__clone( void )
Clone instantiated fields.
Clone instantiated fields.
public
__toString( void )
: string
Returns the header as a string.
Returns the header as a string.
Header fields with empty string values are discarded.
Returns
string
public
__invoke( void )
Sends header fields using the header() function.
Sends header fields using the header() function.
Header fields with empty string values are discarded.
public
offsetExists( mixed $field
)
: boolean
Checks if a header field exists.
Checks if a header field exists.
Parameters
Returns
boolean
Implementation of
ArrayAccess::offsetExists()
public
offsetGet( mixed $field
)
: string|null
Returns a header.
Parameters
Returns
string|null
The header field value or null if it is not defined.
Implementation of
ArrayAccess::offsetGet()
public
offsetSet( string $field
, mixed $value
)
Sets a header field.
Note: Setting a header field to null
removes it, just like unset() would.
Date, Expires, Last-Modified
The Date
, Expires
and Last-Modified
header fields can be provided as a Unix
timestamp, a string or a \DateTime object.
Cache-Control, Content-Disposition and Content-Type
Instances of the ICanBoogie\HTTP\Headers\CacheControl
, ICanBoogie\HTTP\Headers\ContentDisposition
and
ICanBoogie\HTTP\Headers\ContentType
are used to handle the values of the Cache-Control
,
Content-Disposition
and Content-Type
header fields.
Parameters
$field
- The header field to set.
$value
- The value of the header field.
Implementation of
ArrayAccess::offsetSet()
public
offsetUnset( mixed $field
)
Removes a header field.
Parameters
Implementation of
ArrayAccess::offsetUnset()
public
getIterator( void )
Returns an iterator for the header fields.
Returns an iterator for the header fields.
Implementation of
IteratorAggregate::getIterator()