Abstract base class for all header token consumers.
Defines the base parser that loops over tokens, consuming them and creating header parts.
- author Zaahid Bateson
- Children
- Implements
Methods |
public __construct(Psr\Log\LoggerInterface $logger, ZBateson
|
public __invoke(string $value) : array |
Properties |
protected Psr\Log\LoggerInterface $logger |
protected ZBateson
|
protected array $subConsumers = []
|
Methods |
protected advanceToNextToken(Iterator $tokens, bool $isStartToken) : static Determines if the iterator should be advanced to the next token after reading tokens or finding a start token. The default implementation will advance for a start token, but not advance on the end token of the current consumer, allowing the end token to be passed up to a higher-level consumer.
|
protected getAllConsumers() : array Returns this consumer and all unique sub consumers. Loops into the sub-consumers (and their sub-consumers, etc...) finding all unique consumers, and returns them in an array.
|
protected getAllTokenSeparators() : array Returns a list of regular expression markers for this consumer and all sub-consumers by calling getTokenSeparators().
|
protected getConsumerTokenParts(Iterator $tokens) : array 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(). If no sub-consumer is responsible for the current token, calls {@see \AbstractConsumerService::getPartForToken()} and returns it in an array.
|
protected getPartForToken(string $token, bool $isLiteral) : ?ZBateson Constructs and returns an IHeaderPart for the passed string token. If the token should be ignored, the function must return null. The default created part uses the instance's partFactory->newInstance method.
|
protected getTokenParts(Iterator $tokens) : array Returns an array of IHeaderPart for the current token on the iterator. If the current token is a start token from a sub-consumer, the sub- consumer's {@see \AbstractConsumerService::parseTokensIntoParts()} method is called.
|
protected abstract getTokenSeparators() : array Returns an array of regular expression separators specific to this consumer. The returned patterns are used to split the header value into tokens for the consumer to parse into parts. Each array element makes part of a generated regular expression that is used in a call to preg_split(). RegEx patterns can be used, and care should be taken to escape special characters.
|
protected getTokenSplitPattern() : string Returns a regex pattern used to split the input header string. The default implementation calls {@see \AbstractConsumerService::getAllTokenSeparators()} and implodes the returned array with the regex OR '|' character as its glue.
|
protected abstract isEndToken(string $token) : bool Returns true if the passed string token marks the end marker for the current consumer.
|
protected abstract isStartToken(string $token) : bool Returns true if the passed string token marks the beginning marker for the current consumer.
|
protected parseTokensIntoParts(Iterator $tokens) : array Iterates over the passed token Iterator and returns an array of parsed IHeaderPart objects. 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 {@see \AbstractConsumerService::processParts} for any final processing if there are any parts.
|
protected processParts(array $parts) : array 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. The default implementation simply returns the passed array after filtering out null/empty parts.
|
protected splitRawValue( $rawValue) : array Returns an array of split tokens from the input string. The method calls preg_split using {@see \AbstractConsumerService::getTokenSplitPattern()}. The split array will not contain any empty parts and will contain the markers.
|
Properties |
private ?string $tokenSplitPattern = NULL
|
Methods |
private parseRawValue(string $value) : array Parses the raw header value into header parts. Calls splitTokens to split the value into token part strings, then calls parseParts to parse the returned array.
|