Class yii\web\HeaderCollection
| Inheritance | yii\web\HeaderCollection » yii\base\BaseObject |
|---|---|
| Implements | ArrayAccess, Countable, IteratorAggregate, yii\base\Configurable |
| Available since version | 2.0 |
| Source Code | https://github.com/yiisoft/yii2/blob/master/framework/web/HeaderCollection.php |
HeaderCollection is used by yii\web\Response to maintain the currently registered HTTP headers.
Public Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $count | integer | The number of headers in the collection. | yii\web\HeaderCollection |
| $iterator | ArrayIterator | An iterator for traversing the headers in the collection. | yii\web\HeaderCollection |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __call() | Calls the named method which is not a class method. | yii\base\BaseObject |
| __construct() | Constructor. | yii\base\BaseObject |
| __get() | Returns the value of an object property. | yii\base\BaseObject |
| __isset() | Checks if a property is set, i.e. defined and not null. | yii\base\BaseObject |
| __set() | Sets value of an object property. | yii\base\BaseObject |
| __unset() | Sets an object property to null. | yii\base\BaseObject |
| add() | Adds a new header. | yii\web\HeaderCollection |
| canGetProperty() | Returns a value indicating whether a property can be read. | yii\base\BaseObject |
| canSetProperty() | Returns a value indicating whether a property can be set. | yii\base\BaseObject |
| className() | Returns the fully qualified name of this class. | yii\base\BaseObject |
| count() | yii\web\HeaderCollection | |
| fromArray() | Populates the header collection from an array. | yii\web\HeaderCollection |
| get() | Returns the named header(s). | yii\web\HeaderCollection |
| getCount() | yii\web\HeaderCollection | |
| getIterator() | yii\web\HeaderCollection | |
| has() | Returns a value indicating whether the named header exists. | yii\web\HeaderCollection |
| hasMethod() | Returns a value indicating whether a method is defined. | yii\base\BaseObject |
| hasProperty() | Returns a value indicating whether a property is defined. | yii\base\BaseObject |
| init() | Initializes the object. | yii\base\BaseObject |
| offsetExists() | yii\web\HeaderCollection | |
| offsetGet() | yii\web\HeaderCollection | |
| offsetSet() | yii\web\HeaderCollection | |
| offsetUnset() | yii\web\HeaderCollection | |
| remove() | Removes a header. | yii\web\HeaderCollection |
| removeAll() | Removes all headers. | yii\web\HeaderCollection |
| set() | Adds a new header. | yii\web\HeaderCollection |
| setDefault() | Sets a new header only if it does not exist yet. | yii\web\HeaderCollection |
| toArray() | Returns the collection as a PHP array. | yii\web\HeaderCollection |
| toOriginalArray() | Returns the collection as a PHP array but instead of using normalized header names as keys (like toArray()) it uses original header names (case-sensitive). | yii\web\HeaderCollection |
Property Details
The number of headers in the collection.
An iterator for traversing the headers in the collection.
Method Details
Adds a new header.
If there is already a header with the same name, the new one will be appended to it instead of replacing it.
| public $this add ( $name, $value ) | ||
| $name | string | The name of the header |
| $value | string | The value of the header |
| return | $this | The collection object itself |
|---|---|---|
| public void count ( ) |
Populates the header collection from an array.
| public void fromArray ( array $array ) | ||
| $array | array | The headers to populate from |
Returns the named header(s).
| public string|array|null get ( $name, $default = null, $first = true ) | ||
| $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|null | The named header(s). If |
|---|---|---|
| public void getCount ( ) |
| public void getIterator ( ) |
Returns a value indicating whether the named header exists.
| public boolean has ( $name ) | ||
| $name | string | The name of the header |
| return | boolean | Whether the named header exists |
|---|---|---|
| public void offsetExists ( $name ) | ||
| $name | ||
| public void offsetGet ( $name ) | ||
| $name | ||
| public void offsetSet ( $name, $value ) | ||
| $name | ||
| $value | ||
| public void offsetUnset ( $name ) | ||
| $name | ||
Removes a header.
| public array|null remove ( $name ) | ||
| $name | string | The name of the header to be removed. |
| return | array|null | The value of the removed header. Null is returned if the header does not exist. |
|---|---|---|
Removes all headers.
| public void removeAll ( ) |
Adds a new header.
If there is already a header with the same name, it will be replaced.
| public $this set ( $name, $value = '' ) | ||
| $name | string | The name of the header |
| $value | string | The value of the header |
| return | $this | The collection object itself |
|---|---|---|
Sets a new header only if it does not exist yet.
If there is already a header with the same name, the new one will be ignored.
| public $this setDefault ( $name, $value ) | ||
| $name | string | The name of the header |
| $value | string | The value of the header |
| return | $this | The collection object itself |
|---|---|---|
Returns the collection as a PHP array.
| public array toArray ( ) | ||
| return | array | The array representation of the collection. The array keys are header names, and the array values are the corresponding header values. |
|---|---|---|
Returns the collection as a PHP array but instead of using normalized header names as keys (like toArray()) it uses original header names (case-sensitive).
| public array toOriginalArray ( ) | ||
| return | array | The array representation of the collection. |
|---|---|---|