PHP Class Neos\Flow\Http\Headers

Mostra file Open project: neos/flow-development-collection Class Usage Examples

Protected Properties

Property Type Description
$cacheDirectives array
$cookies array
$fields array

Public Methods

Method Description
__construct ( array $fields = [] ) Constructs a new Headers object.
createFromServer ( array $server ) : Headers Creates a new Headers instance from the given $_SERVER-superglobal-like array.
eatCookie ( string $name ) : void Although not 100% semantically correct, an alias for removeCookie()
get ( string $name ) : array | string Returns the specified HTTP header
getAll ( ) : array Returns all header fields
getCacheControlDirective ( string $name ) : mixed Returns the value of the specified Cache-Control directive.
getCookie ( string $name ) : Cookie Returns a cookie specified by the given name
getCookies ( ) : array Returns all cookies
has ( string $name ) : boolean Checks if the specified HTTP header exists
hasCookie ( string $name ) : boolean Checks if the specified cookie exists
remove ( string $name ) : void Removes the specified header field
removeCacheControlDirective ( string $name ) : void Removes a special directive previously set for the Cache-Control header.
removeCookie ( string $name ) : void Removes the specified cookie if it exists
set ( string $name, array | string | DateTime $values, boolean $replaceExistingHeader = true ) : void Sets the specified HTTP header
setCacheControlDirective ( string $name, string $value = null ) : void Sets a special directive for use in the Cache-Control header, according to RFC 2616 / 14.9
setCookie ( Cookie $cookie ) : void Sets a cookie

Protected Methods

Method Description
getCacheControlHeader ( ) : string Renders and returns a Cache-Control header, based on the previously set cache control directives.
setCacheControlDirectivesFromRawHeader ( string $rawFieldValue ) : void Internally sets the cache directives correctly by parsing the given Cache-Control field value.
setCookiesFromRawHeader ( string $rawFieldValue ) : void Internally sets cookie objects based on the Cookie header field value.

Method Details

__construct() public method

Constructs a new Headers object.
public __construct ( array $fields = [] )
$fields array Field names and their values (either as single value or array of values)

createFromServer() public static method

Creates a new Headers instance from the given $_SERVER-superglobal-like array.
public static createFromServer ( array $server ) : Headers
$server array An array similar or equal to $_SERVER, containing headers in the form of "HTTP_FOO_BAR"
return Headers

eatCookie() public method

Although not 100% semantically correct, an alias for removeCookie()
public eatCookie ( string $name ) : void
$name string Name of the cookie to eat
return void

get() public method

Dates are returned as DateTime objects with the timezone set to GMT.
public get ( string $name ) : array | string
$name string Name of the header, for example "Location", "Content-Description" etc.
return array | string An array of field values if multiple headers of that name exist, a string value if only one value exists and NULL if there is no such header.

getAll() public method

Note that even for those header fields which exist only one time, the value is returned as an array (with a single item).
public getAll ( ) : array
return array

getCacheControlDirective() public method

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.
public getCacheControlDirective ( string $name ) : mixed
$name string Name of the cache directive, for example "max-age"
return mixed

getCacheControlHeader() protected method

Renders and returns a Cache-Control header, based on the previously set cache control directives.
See also: get()
protected getCacheControlHeader ( ) : string
return string Either the value of the header or NULL if it shall be omitted

getCookie() public method

Returns a cookie specified by the given name
public getCookie ( string $name ) : Cookie
$name string Name of the cookie
return Cookie The cookie or NULL if no such cookie exists

getCookies() public method

Returns all cookies
public getCookies ( ) : array
return array

has() public method

Checks if the specified HTTP header exists
public has ( string $name ) : boolean
$name string Name of the header
return boolean

hasCookie() public method

Checks if the specified cookie exists
public hasCookie ( string $name ) : boolean
$name string Name of the cookie
return boolean

remove() public method

Removes the specified header field
public remove ( string $name ) : void
$name string Name of the field
return void

removeCacheControlDirective() public method

Removes a special directive previously set for the Cache-Control header.
public removeCacheControlDirective ( string $name ) : void
$name string Name of the directive, for example "public"
return void

removeCookie() public method

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.
public removeCookie ( string $name ) : void
$name string Name of the cookie to remove
return void

set() public method

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.
public set ( string $name, array | string | DateTime $values, boolean $replaceExistingHeader = true ) : void
$name string Name of the header, for example "Location", "Content-Description" etc.
$values array | string | DateTime An array of values or a single value for the specified header field
$replaceExistingHeader boolean If a header with the same name should be replaced. Default is TRUE.
return void

setCacheControlDirective() public method

Sets a special directive for use in the Cache-Control header, according to RFC 2616 / 14.9
public setCacheControlDirective ( string $name, string $value = null ) : void
$name string Name of the directive, for example "max-age"
$value string An optional value
return void

setCacheControlDirectivesFromRawHeader() protected method

Internally sets the cache directives correctly by parsing the given Cache-Control field value.
See also: set()
protected setCacheControlDirectivesFromRawHeader ( string $rawFieldValue ) : void
$rawFieldValue string The value of a specification compliant Cache-Control header
return void

setCookie() public method

Sets a cookie
public setCookie ( Cookie $cookie ) : void
$cookie Cookie
return void

setCookiesFromRawHeader() protected method

Internally sets cookie objects based on the Cookie header field value.
See also: set()
protected setCookiesFromRawHeader ( string $rawFieldValue ) : void
$rawFieldValue string The value of a specification compliant Cookie header
return void

Property Details

$cacheDirectives protected_oe property

protected array $cacheDirectives
return array

$cookies protected_oe property

protected array $cookies
return array

$fields protected_oe property

protected array $fields
return array