Maintains a collection of headers for a part.

author Zaahid Bateson
package MailMimeParser

 Methods

Constructor

__construct(\ZBateson\MailMimeParser\Header\HeaderFactory $headerFactory) 

Parameters

$headerFactory

\ZBateson\MailMimeParser\Header\HeaderFactory

Adds the header to the collection.

add(string $name, string $value) 

Parameters

$name

string

$value

string

Returns true if the passed header exists in this collection.

exists(string $name, integer $offset = 0) : boolean

Parameters

$name

string

$offset

integer

Returns

boolean

Returns the AbstractHeader object for the header with the given $name and at the optional offset (defaulting to the first header in the collection where more than one header with the same name exists).

get(string $name, integer $offset = 0) : \ZBateson\MailMimeParser\Header\AbstractHeader

Note that mime headers aren't case sensitive.

Parameters

$name

string

$offset

integer

Returns

\ZBateson\MailMimeParser\Header\AbstractHeader

Returns all headers with the passed name.

getAll(string $name) : array<mixed,\ZBateson\MailMimeParser\Header\AbstractHeader>

Parameters

$name

string

Returns

array<mixed,\ZBateson\MailMimeParser\Header\AbstractHeader>

Returns an array of AbstractHeader objects representing all headers in this collection.

getHeaderObjects() : \ZBateson\MailMimeParser\Header\AbstractHeader

Returns

\ZBateson\MailMimeParser\Header\AbstractHeader

Returns an array of headers in this collection. Each returned element in the array is an array with the first element set to the name, and the second its value:

getHeaders() : array<mixed,string[]>

[ [ 'Header-Name', 'Header Value' ], [ 'Second-Header-Name', 'Second-Header-Value' ], // etc... ]

Returns

array<mixed,string[]>

Returns an iterator to the headers in this collection. Each returned element is an array with its first element set to the header's name, and the second to its value:

getIterator() : \ArrayIterator

[ 'Header-Name', 'Header Value' ]

Returns

\ArrayIterator

Removes the header from the collection with the passed name. Defaults to removing the first instance of the header for a collection that contains more than one with the same passed name.

remove(string $name, integer $offset = 0) : boolean

Parameters

$name

string

$offset

integer

Returns

boolean

Removes all headers that match the passed name.

removeAll(string $name) : boolean

Parameters

$name

string

Returns

boolean

If a header exists with the passed name, and at the passed offset if more than one exists, its value is updated.

set(string $name, string $value, integer $offset = 0

If a header with the passed name doesn't exist at the passed offset, it is created at the next available offset (offset is ignored when adding).

Parameters

$name

string

$value

string

$offset

integer

Returns the header in the headers array at the passed 0-based integer index.

getByIndex(integer $index) : \ZBateson\MailMimeParser\Header\AbstractHeader

Parameters

$index

integer

Returns

\ZBateson\MailMimeParser\Header\AbstractHeader

Returns the string in lower-case, and with non-alphanumeric characters stripped out.

getNormalizedHeaderName(string $header) : string

Parameters

$header

string

Returns

string

 Properties

 

the HeaderFactory object used for created headers

$headerFactory : \ZBateson\MailMimeParser\Header\HeaderFactory

Default

 

Maps header names by their "normalized" (lower-cased, non-alphanumeric characters stripped) name to an array of indexes in the $headers array. For example: $headerMap['contenttype] = [ 1, 4 ] would indicate that the headers in $headers[1] and $headers[4] are both headers with the name 'Content-Type' or 'contENTtype'.

$headerMap : array

Default

array()
 

Each element is an AbstractHeader representing the header at the same index in the $headers array. If an AbstractHeader has not been constructed for the header at that index, the element would be set to null.

$headerObjects : array<mixed,\ZBateson\MailMimeParser\Header\AbstractHeader>

Default

array()
 

Each element in the array is an array with its first element set to the header's name, and the second its value.

$headers : array<mixed,string[]>

Default

array()
 

the next index to use for $headers and $headerObjects.

$nextIndex : integer

Default

0