Copied!

Reads headers separated into parameters consisting of an optional main value, and subsequent name/value pairs - for example text/html; charset=utf-8.

A ParameterConsumerService's parts are separated by a semi-colon. Its name/value pairs are separated with an '=' character.

Parts may be mime-encoded entities, or RFC-2231 split/encoded parts. Additionally, a value can be quoted and comments may exist.

Actual processing of parameters is done in ParameterNameValueConsumerService, with ParameterConsumerService processing all collected parts into split parameter parts as necessary.

CloneableInstantiable
Methods
public __construct(Psr\Log\LoggerInterface $logger, ZBateson\MailMimeParser\Header\Part\HeaderPartFactory $partFactory, ZBateson\MailMimeParser\Header\Consumer\ParameterNameValueConsumerService $parameterNameValueConsumerService, ZBateson\MailMimeParser\Header\Consumer\CommentConsumerService $commentConsumerService, ZBateson\MailMimeParser\Header\Consumer\QuotedStringConsumerService $quotedStringConsumerService)
public ZBateson\MailMimeParser\Header\Consumer\AbstractConsumerService::__invoke(string $value) : array
Properties
protected Psr\Log\LoggerInterface ZBateson\MailMimeParser\Header\Consumer\AbstractConsumerService::$logger
protected ZBateson\MailMimeParser\Header\Part\HeaderPartFactory ZBateson\MailMimeParser\Header\Consumer\AbstractConsumerService::$partFactory
 
  • var \HeaderPartFactory used to construct IHeaderPart objects
protected array ZBateson\MailMimeParser\Header\Consumer\AbstractConsumerService::$subConsumers = []
 
  • var \AbstractConsumerService[] array of sub-consumers used by this consumer if any, or an empty array if none exist.
Methods
protected advanceToNextToken(Iterator $tokens, bool $isStartToken) : static
 

Disables advancing for start tokens.

protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumerService::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.

  • return \AbstractConsumerService[] Array of unique consumers.
protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumerService::getAllTokenSeparators() : array
 

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

  • return string[] Array of regular expression markers.
protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumerService::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.

  • param \Iterator<string> $tokens
  • return \IHeaderPart[]
protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumerService::getPartForToken(string $token, bool $isLiteral) : ?ZBateson\MailMimeParser\Header\IHeaderPart
 

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.

  • param string $token the token
  • param bool $isLiteral set to true if the token represents a literal - e.g. an escaped token
  • return ?\IHeaderPart The constructed header part or null if the token should be ignored.
protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumerService::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.

  • param \Iterator<string> $tokens The token iterator.
  • return \IHeaderPart[]
protected ZBateson\MailMimeParser\Header\Consumer\AbstractGenericConsumerService::getTokenSeparators() : array
 

Returns the regex '\s+' (whitespace) pattern matcher as a token marker so the header value is split along whitespace characters.

  • return string[] an array of regex pattern matchers
protected getTokenSplitPattern() : string
 

Overridden to use a specialized regex for finding mime-encoded parts (RFC 2047).

Some implementations seem to place mime-encoded parts within quoted parameters, and split the mime-encoded parts across multiple split parameters. The specialized regex doesn't allow double quotes inside a mime encoded part, so it can be "continued" in another parameter.

  • return string the regex pattern
protected ZBateson\MailMimeParser\Header\Consumer\AbstractGenericConsumerService::isEndToken(string $token) : bool
 

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

protected ZBateson\MailMimeParser\Header\Consumer\AbstractGenericConsumerService::isStartToken(string $token) : bool
 

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

  • codeCoverageIgnore
protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumerService::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.

  • param \Iterator<string> $tokens An iterator over a string of tokens
  • return \IHeaderPart[] An array of parsed parts
protected processParts(array $parts) : array
 

Post processing involves looking for split parameter parts with matching names and combining them into a SplitParameterPart, and otherwise returning ParameterParts from ParameterNameValueConsumer as-is.

  • param \IHeaderPart[] $parts The parsed parts.
  • return \IHeaderPart[] Array of resulting final parts.
protected ZBateson\MailMimeParser\Header\Consumer\AbstractConsumerService::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.

  • param string $rawValue the raw string
  • return string[] the array of tokens
© 2025 Bruce Wells
Search Namespaces \ Classes
Configuration