PHP Class yii\web\HeaderCollection

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

Méthodes publiques

Méthode 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 méthode

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 méthode

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

fromArray() public méthode

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

get() public méthode

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.
Résultat 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 méthode

Returns the number of headers in the collection.
public getCount ( ) : integer
Résultat integer the number of headers in the collection.

getIterator() public méthode

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
Résultat ArrayIterator an iterator for traversing the headers in the collection.

has() public méthode

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

offsetExists() public méthode

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
Résultat boolean whether the named header exists

offsetGet() public méthode

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
Résultat string the header value with the specified name, null if the named header does not exist.

offsetSet() public méthode

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 méthode

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 méthode

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

removeAll() public méthode

Removes all headers.
public removeAll ( )

set() public méthode

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 méthode

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 méthode

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