PHP Class yii\web\HeaderCollection

Since: 2.0
Author: Qiang Xue ([email protected])
Inheritance: extends yii\base\Object, implements IteratorAggregate, implements ArrayAccess, implements Countable
Show file Open project: yiisoft/yii2 Class Usage Examples

Public Methods

Method Description
add ( string $name, string $value ) Adds a new header.
count ( ) : integer Returns the number of headers in the collection.
fromArray ( array $array ) Populates the header collection from an array.
get ( string $name, mixed $default = null, boolean $first = true ) : string | array Returns the named header(s).
getCount ( ) : integer Returns the number of headers in the collection.
getIterator ( ) : ArrayIterator Returns an iterator for traversing the headers in the collection.
has ( string $name ) : boolean Returns a value indicating whether the named header exists.
offsetExists ( string $name ) : boolean Returns whether there is a header with the specified name.
offsetGet ( string $name ) : string Returns the header with the specified name.
offsetSet ( string $name, string $value ) Adds the header to the collection.
offsetUnset ( string $name ) Removes the named header.
remove ( string $name ) : array Removes a header.
removeAll ( ) Removes all headers.
set ( string $name, string $value = '' ) Adds a new header.
setDefault ( string $name, string $value ) Sets a new header only if it does not exist yet.
toArray ( ) : array Returns the collection as a PHP array.

Method Details

add() public method

If there is already a header with the same name, the new one will be appended to it instead of replacing it.
public add ( string $name, string $value )
$name string the name of the header
$value string the value of the header

count() public method

This method is required by the SPL Countable interface. It will be implicitly called when you use count($collection).
public count ( ) : integer
return integer the number of headers in the collection.

fromArray() public method

Populates the header collection from an array.
Since: 2.0.3
public fromArray ( array $array )
$array array the headers to populate from

get() public method

Returns the named header(s).
public get ( string $name, mixed $default = null, boolean $first = true ) : string | array
$name string the name of the header to return
$default mixed the value to return in case the named header does not exist
$first boolean whether to only return the first header of the specified name. If false, all headers of the specified name will be returned.
return string | array the named header(s). If `$first` is true, a string will be returned; If `$first` is false, an array will be returned.

getCount() public method

Returns the number of headers in the collection.
public getCount ( ) : integer
return integer the number of headers in the collection.

getIterator() public method

This method is required by the SPL interface [[\IteratorAggregate]]. It will be implicitly called when you use foreach to traverse the collection.
public getIterator ( ) : ArrayIterator
return ArrayIterator an iterator for traversing the headers in the collection.

has() public method

Returns a value indicating whether the named header exists.
public has ( string $name ) : boolean
$name string the name of the header
return boolean whether the named header exists

offsetExists() public method

This method is required by the SPL interface [[\ArrayAccess]]. It is implicitly called when you use something like isset($collection[$name]).
public offsetExists ( string $name ) : boolean
$name string the header name
return boolean whether the named header exists

offsetGet() public method

This method is required by the SPL interface [[\ArrayAccess]]. It is implicitly called when you use something like $header = $collection[$name];. This is equivalent to HeaderCollection::get.
public offsetGet ( string $name ) : string
$name string the header name
return string the header value with the specified name, null if the named header does not exist.

offsetSet() public method

This method is required by the SPL interface [[\ArrayAccess]]. It is implicitly called when you use something like $collection[$name] = $header;. This is equivalent to HeaderCollection::add.
public offsetSet ( string $name, string $value )
$name string the header name
$value string the header value to be added

offsetUnset() public method

This method is required by the SPL interface [[\ArrayAccess]]. It is implicitly called when you use something like unset($collection[$name]). This is equivalent to HeaderCollection::remove.
public offsetUnset ( string $name )
$name string the header name

remove() public method

Removes a header.
public remove ( string $name ) : array
$name string the name of the header to be removed.
return array the value of the removed header. Null is returned if the header does not exist.

removeAll() public method

Removes all headers.
public removeAll ( )

set() public method

If there is already a header with the same name, it will be replaced.
public set ( string $name, string $value = '' )
$name string the name of the header
$value string the value of the header

setDefault() public method

If there is already a header with the same name, the new one will be ignored.
public setDefault ( string $name, string $value )
$name string the name of the header
$value string the value of the header

toArray() public method

Returns the collection as a PHP array.
public toArray ( ) : array
return array the array representation of the collection. The array keys are header names, and the array values are the corresponding header values.