MailMimeParser 2.3

AddressBaseConsumer extends AbstractConsumer
in package

Serves as a base-consumer for recipient/sender email address headers (like From and To).

AddressBaseConsumer passes on token processing to its sub-consumer, an AddressConsumer, and collects Part\AddressPart objects processed and returned by AddressConsumer.

Tags
author

Zaahid Bateson

Table of Contents

$consumerService  : ConsumerService
$partFactory  : HeaderPartFactory
__construct()  : mixed
__invoke()  : array<string|int, IHeaderPart>
Invokes parsing of a header's value into header parts.
getInstance()  : mixed
Returns the singleton instance for the class.
advanceToNextToken()  : static
Disables advancing for start tokens.
getAllConsumers()  : array<string|int, AbstractConsumer>
Returns this consumer and all unique sub consumers.
getAllTokenSeparators()  : array<string|int, string>
Returns a list of regular expression markers for this consumer and all sub-consumers by calling getTokenSeparators().
getConsumerTokenParts()  : array<string|int, IHeaderPart>
Iterates through this consumer's sub-consumers checking if the current token triggers a sub-consumer's start token and passes control onto that sub-consumer's parseTokenIntoParts().
getPartForToken()  : HeaderPart|null
Never reached by AddressBaseConsumer. Overridden to satisfy AbstractConsumer.
getSubConsumers()  : array<string|int, AbstractConsumer>
Returns \ZBateson\MailMimeParser\Header\Consumer\AddressConsumer as a sub-consumer.
getTokenParts()  : array<string|int, IHeaderPart>|array<string|int, mixed>
Overridden so tokens aren't handled at this level, and instead are passed on to AddressConsumer.
getTokenSeparators()  : array<string|int, string>
Returns an empty array.
getTokenSplitPattern()  : string
Returns a regex pattern used to split the input header string.
isEndToken()  : false
AddressBaseConsumer doesn't have start/end tokens, and so always returns false.
isStartToken()  : false
AddressBaseConsumer doesn't have start/end tokens, and so always returns false.
parseTokensIntoParts()  : array<string|int, IHeaderPart>
Iterates over the passed token Iterator and returns an array of parsed IHeaderPart objects.
processParts()  : array<string|int, IHeaderPart>
Performs any final processing on the array of parsed parts before returning it to the consumer client.
splitRawValue()  : array<string|int, mixed>
Returns an array of split tokens from the input string.
parseRawValue()  : array<string|int, IHeaderPart>
Parses the raw header value into header parts.

Properties

Methods

__invoke()

Invokes parsing of a header's value into header parts.

public __invoke(string $value) : array<string|int, IHeaderPart>
Parameters
$value : string

the raw header value

Return values
array<string|int, IHeaderPart>

the array of parsed parts

advanceToNextToken()

Disables advancing for start tokens.

protected advanceToNextToken(Iterator $tokens, bool $isStartToken) : static

The start token for AddressBaseConsumer is part of an AddressPart (or a sub-consumer) and so must be passed on.

Parameters
$tokens : Iterator

The token iterator.

$isStartToken : bool

true for the start token.

Return values
static

getAllConsumers()

Returns this consumer and all unique sub consumers.

protected getAllConsumers() : array<string|int, AbstractConsumer>

Loops into the sub-consumers (and their sub-consumers, etc...) finding all unique consumers, and returns them in an array.

Return values
array<string|int, AbstractConsumer>

Array of unique consumers.

getAllTokenSeparators()

Returns a list of regular expression markers for this consumer and all sub-consumers by calling getTokenSeparators().

protected getAllTokenSeparators() : array<string|int, string>
Return values
array<string|int, string>

Array of regular expression markers.

getConsumerTokenParts()

Iterates through this consumer's sub-consumers checking if the current token triggers a sub-consumer's start token and passes control onto that sub-consumer's parseTokenIntoParts().

protected getConsumerTokenParts(Iterator $tokens) : array<string|int, IHeaderPart>

If no sub-consumer is responsible for the current token, calls AbstractConsumer::getPartForToken() and returns it in an array.

Parameters
$tokens : Iterator
Return values
array<string|int, IHeaderPart>

getPartForToken()

Never reached by AddressBaseConsumer. Overridden to satisfy AbstractConsumer.

protected getPartForToken(string $token, bool $isLiteral) : HeaderPart|null
Parameters
$token : string

the token

$isLiteral : bool

set to true if the token represents a literal - e.g. an escaped token

Tags
codeCoverageIgnore
Return values
HeaderPart|null

the constructed header part or null if the token should be ignored

getTokenParts()

Overridden so tokens aren't handled at this level, and instead are passed on to AddressConsumer.

protected getTokenParts(Iterator $tokens) : array<string|int, IHeaderPart>|array<string|int, mixed>
Parameters
$tokens : Iterator

The token iterator.

Return values
array<string|int, IHeaderPart>|array<string|int, mixed>

getTokenSeparators()

Returns an empty array.

protected getTokenSeparators() : array<string|int, string>
Return values
array<string|int, string>

an array of regex pattern matchers

getTokenSplitPattern()

Returns a regex pattern used to split the input header string.

protected getTokenSplitPattern() : string

The default implementation calls AbstractConsumer::getAllTokenSeparators() and implodes the returned array with the regex OR '|' character as its glue.

Return values
string

the regex pattern

isEndToken()

AddressBaseConsumer doesn't have start/end tokens, and so always returns false.

protected isEndToken(string $token) : false
Parameters
$token : string

The current token

Return values
false

isStartToken()

AddressBaseConsumer doesn't have start/end tokens, and so always returns false.

protected isStartToken(string $token) : false
Parameters
$token : string

The current token

Tags
codeCoverageIgnore
Return values
false

parseTokensIntoParts()

Iterates over the passed token Iterator and returns an array of parsed IHeaderPart objects.

protected parseTokensIntoParts(Iterator $tokens) : array<string|int, IHeaderPart>

The method checks each token to see if the token matches a sub-consumer's start token, or if it matches the current consumer's end token to stop processing.

If a sub-consumer's start token is matched, the sub-consumer is invoked and its returned parts are merged to the current consumer's header parts.

After all tokens are read and an array of Header\Parts are constructed, the array is passed to AbstractConsumer::processParts for any final processing.

Parameters
$tokens : Iterator

An iterator over a string of tokens

Return values
array<string|int, IHeaderPart>

An array of parsed parts

processParts()

Performs any final processing on the array of parsed parts before returning it to the consumer client.

protected processParts(array<string|int, IHeaderPart$parts) : array<string|int, IHeaderPart>

The default implementation simply returns the passed array after filtering out null/empty parts.

Parameters
$parts : array<string|int, IHeaderPart>

The parsed parts.

Return values
array<string|int, IHeaderPart>

Array of resulting final parts.

splitRawValue()

Returns an array of split tokens from the input string.

protected splitRawValue(string $rawValue) : array<string|int, mixed>

The method calls preg_split using AbstractConsumer::getTokenSplitPattern(). The split array will not contain any empty parts and will contain the markers.

Parameters
$rawValue : string

the raw string

Return values
array<string|int, mixed>

the array of tokens

parseRawValue()

Parses the raw header value into header parts.

private parseRawValue(string $value) : array<string|int, IHeaderPart>

Calls splitTokens to split the value into token part strings, then calls parseParts to parse the returned array.

Parameters
$value : string
Return values
array<string|int, IHeaderPart>

the array of parsed parts

Search results