ReceivedConsumerService
extends AbstractConsumerService
in package
Parses a Received header into ReceivedParts, ReceivedDomainParts, a DatePart, and CommentParts.
Parts that don't correspond to any of the above are discarded.
Tags
Table of Contents
- $logger : LoggerInterface
- $partFactory : HeaderPartFactory
- $subConsumers : array<string|int, mixed>
- $tokenSplitPattern : string|null
- __construct() : mixed
- __invoke() : array<string|int, IHeaderPart>
- Invokes parsing of a header's value into header parts.
- advanceToNextToken() : static
- Overridden to /not/ advance when the end token matches a start token for a sub-consumer.
- getAllConsumers() : array<string|int, AbstractConsumerService>
- 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() : IHeaderPart|null
- Constructs and returns an IHeaderPart for the passed string token.
- getTokenParts() : array<string|int, IHeaderPart>
- Returns an array of IHeaderPart for the current token on the iterator.
- getTokenSeparators() : array<string|int, string>
- ReceivedConsumerService doesn't have any token separators of its own.
- getTokenSplitPattern() : string
- Overridden to exclude the MimeLiteralPart pattern that comes by default in AbstractConsumer.
- isEndToken() : bool
- ReceivedConsumerService doesn't have an end token, and so this just returns false.
- isStartToken() : bool
- ReceivedConsumerService doesn't start consuming at a specific token, it's the base handler for the Received header, and so this 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. The passed $parts array is guaranteed to not be empty.
- splitRawValue() : array<string|int, string>
- Returns an array of split tokens from the input string.
- parseRawValue() : array<string|int, IHeaderPart>
- Parses the raw header value into header parts.
Properties
$logger
protected
LoggerInterface
$logger
$partFactory
protected
HeaderPartFactory
$partFactory
used to construct IHeaderPart objects
$subConsumers
protected
array<string|int, mixed>
$subConsumers
= []
array of sub-consumers used by this consumer if any, or an empty array if none exist.
$tokenSplitPattern
private
string|null
$tokenSplitPattern
= null
the generated token split pattern on first run, so it doesn't need to be regenerated every time.
Methods
__construct()
public
__construct(LoggerInterface $logger, HeaderPartFactory $partFactory, DomainConsumerService $fromDomainConsumerService, DomainConsumerService $byDomainConsumerService, GenericReceivedConsumerService $viaGenericReceivedConsumerService, GenericReceivedConsumerService $withGenericReceivedConsumerService, GenericReceivedConsumerService $idGenericReceivedConsumerService, GenericReceivedConsumerService $forGenericReceivedConsumerService, ReceivedDateConsumerService $receivedDateConsumerService, CommentConsumerService $commentConsumerService) : mixed
Parameters
- $logger : LoggerInterface
- $partFactory : HeaderPartFactory
- $fromDomainConsumerService : DomainConsumerService
- $byDomainConsumerService : DomainConsumerService
- $viaGenericReceivedConsumerService : GenericReceivedConsumerService
- $withGenericReceivedConsumerService : GenericReceivedConsumerService
- $idGenericReceivedConsumerService : GenericReceivedConsumerService
- $forGenericReceivedConsumerService : GenericReceivedConsumerService
- $receivedDateConsumerService : ReceivedDateConsumerService
- $commentConsumerService : CommentConsumerService
Return values
mixed —__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()
Overridden to /not/ advance when the end token matches a start token for a sub-consumer.
protected
advanceToNextToken(Iterator $tokens, bool $isStartToken) : static
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, AbstractConsumerService>
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, AbstractConsumerService> —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<string|int, string> $tokens) : array<string|int, IHeaderPart>
If no sub-consumer is responsible for the current token, calls AbstractConsumerService::getPartForToken() and returns it in an array.
Parameters
- $tokens : Iterator<string|int, string>
Return values
array<string|int, IHeaderPart> —getPartForToken()
Constructs and returns an IHeaderPart for the passed string token.
protected
getPartForToken(string $token, bool $isLiteral) : IHeaderPart|null
If the token should be ignored, the function must return null.
The default created part uses the instance's partFactory->newInstance method.
Parameters
- $token : string
-
the token
- $isLiteral : bool
-
set to true if the token represents a literal - e.g. an escaped token
Return values
IHeaderPart|null —The constructed header part or null if the token should be ignored.
getTokenParts()
Returns an array of IHeaderPart for the current token on the iterator.
protected
getTokenParts(Iterator<string|int, string> $tokens) : array<string|int, IHeaderPart>
If the current token is a start token from a sub-consumer, the sub- consumer's AbstractConsumerService::parseTokensIntoParts() method is called.
Parameters
- $tokens : Iterator<string|int, string>
-
The token iterator.
Return values
array<string|int, IHeaderPart> —getTokenSeparators()
ReceivedConsumerService doesn't have any token separators of its own.
protected
getTokenSeparators() : array<string|int, string>
Sub-Consumers will return separators matching 'part' word separators, for example 'from' and 'by', and ';' for date, etc...
Return values
array<string|int, string> —an array of regex pattern matchers
getTokenSplitPattern()
Overridden to exclude the MimeLiteralPart pattern that comes by default in AbstractConsumer.
protected
getTokenSplitPattern() : string
Return values
string —the regex pattern
isEndToken()
ReceivedConsumerService doesn't have an end token, and so this just returns false.
protected
isEndToken(string $token) : bool
Parameters
- $token : string
-
The current token
Return values
bool —isStartToken()
ReceivedConsumerService doesn't start consuming at a specific token, it's the base handler for the Received header, and so this always returns false.
protected
isStartToken(string $token) : bool
Parameters
- $token : string
-
The current token
Tags
Return values
bool —parseTokensIntoParts()
Iterates over the passed token Iterator and returns an array of parsed IHeaderPart objects.
protected
parseTokensIntoParts(Iterator<string|int, string> $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 AbstractConsumerService::processParts for any final processing if there are any parts.
Parameters
- $tokens : Iterator<string|int, string>
-
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. The passed $parts array is guaranteed to not be empty.
protected
processParts(array<string|int, IHeaderPart> $parts) : array<string|int, IHeaderPart>
Parameters
- $parts : array<string|int, IHeaderPart>
Return values
array<string|int, IHeaderPart> —splitRawValue()
Returns an array of split tokens from the input string.
protected
splitRawValue(string $rawValue) : array<string|int, string>
The method calls preg_split using AbstractConsumerService::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, string> —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