Headers deprecated
class Headers implements Iterator (View source)
deprecated
Container for HTTP header fields
Properties
protected array | $fields | ||
protected array | $cookies | ||
protected array | $cacheDirectives |
Methods
Constructs a new Headers object.
Creates a new Headers instance from the given $_SERVER-superglobal-like array.
Get raw header values
Returns the specified HTTP header
Returns all header fields
Checks if the specified HTTP header exists
Removes the specified header field
Returns all cookies
Checks if the specified cookie exists
Removes the specified cookie if it exists
Although not 100% semantically correct, an alias for removeCookie()
Sets a special directive for use in the Cache-Control header, according to RFC 2616 / 14.9
Removes a special directive previously set for the Cache-Control header.
Returns the value of the specified Cache-Control directive.
Internally sets the cache directives correctly by parsing the given Cache-Control field value.
Renders and returns a Cache-Control header, based on the previously set cache control directives.
Internally sets cookie objects based on the Cookie header field value.
Get all header lines prepared as "name: value" strings.
Renders this headers object as string, with lines separated by "\r\n" as required by RFC 2616 sec 5.
No description
No description
No description
No description
No description
Details
__construct(array $fields = [])
Constructs a new Headers object.
static Headers
createFromServer(array $server)
Creates a new Headers instance from the given $_SERVER-superglobal-like array.
void
set(string $name, array|string|DateTime $values, bool $replaceExistingHeader = true)
Sets the specified HTTP header
DateTime objects will be converted to a string representation internally but will be returned as DateTime objects on calling get().
Please note that dates are normalized to GMT internally, so that get() will return the same point in time, but not necessarily in the same timezone, if it was not GMT previously. GMT is used synonymously with UTC as per RFC 2616 3.3.1.
array
getRaw(string $name)
Get raw header values
array|string
get(string $name)
Returns the specified HTTP header
Dates are returned as DateTime objects with the timezone set to GMT.
array
getAll()
Returns all header fields
Note that even for those header fields which exist only one time, the value is returned as an array (with a single item).
bool
has(string $name)
Checks if the specified HTTP header exists
void
remove(string $name)
Removes the specified header field
void
setCookie(Cookie $cookie)
Sets a cookie
Cookie
getCookie(string $name)
Returns a cookie specified by the given name
Cookie[]
getCookies()
Returns all cookies
bool
hasCookie(string $name)
Checks if the specified cookie exists
void
removeCookie(string $name)
Removes the specified cookie if it exists
Note: This will remove the cookie object from this Headers container. If you intend to remove a cookie in the user agent (browser), you should call the cookie's expire() method and not remove the cookie from the Headers container.
void
eatCookie(string $name)
Although not 100% semantically correct, an alias for removeCookie()
void
setCacheControlDirective(string $name, string $value = null)
Sets a special directive for use in the Cache-Control header, according to RFC 2616 / 14.9
void
removeCacheControlDirective(string $name)
Removes a special directive previously set for the Cache-Control header.
mixed
getCacheControlDirective(string $name)
Returns the value of the specified Cache-Control directive.
If the cache directive is not present, NULL is returned. If the specified directive is present but contains no value, this method returns true. Finally, if the directive is present and does contain a value, the value is returned.
protected void
setCacheControlDirectivesFromRawHeader(string $rawFieldValue)
Internally sets the cache directives correctly by parsing the given Cache-Control field value.
protected string
getCacheControlHeader()
Renders and returns a Cache-Control header, based on the previously set cache control directives.
protected void
setCookiesFromRawHeader(string $rawFieldValue)
Internally sets cookie objects based on the Cookie header field value.
array
getPreparedValues()
Get all header lines prepared as "name: value" strings.
string
__toString()
Renders this headers object as string, with lines separated by "\r\n" as required by RFC 2616 sec 5.
string[]|mixed
current()
No description
void
next()
No description
mixed
key()
No description
bool
valid()
No description
void
rewind()
No description