QuotedStringConsumer
extends GenericConsumer
in package
Represents a quoted part of a header value starting at a double quote, and ending at the next double quote.
A quoted-pair part in a header is a literal. There are no sub-consumers for it and a Part\LiteralPart is returned.
Newline characters (CR and LF) are stripped entirely from the quoted part. This is based on the example at:
https://tools.ietf.org/html/rfc822#section-3.1.1
And https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html in section 7.2.1 splitting the boundary.
Tags
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.
- getSubConsumers() : array<string|int, AbstractConsumer>
- QuotedStringConsumer doesn't have any sub-consumers. This method returns an empty array.
- advanceToNextToken() : static
- Determines if the iterator should be advanced to the next token after reading tokens or finding a start token.
- filterIgnoredSpaces() : array<string|int, HeaderPart>
- No ignored spaces in a quoted part. Returns the passed $parts param as-is.
- 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() : IHeaderPart|null
- Constructs a LiteralPart and returns it.
- getTokenParts() : array<string|int, IHeaderPart>
- Returns an array of IHeaderPart for the current token on the iterator.
- getTokenSeparators() : array<string|int, string>
- Returns a single regex pattern for a double quote.
- getTokenSplitPattern() : string
- Returns a regex pattern used to split the input header string.
- isEndToken() : bool
- Returns true if the token is a double quote.
- isStartToken() : bool
- Returns true if the token is a double quote.
- 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.
- addSpaces() : self
- Checks if the passed space part should be added to the returned parts and adds it.
- addSpaceToRetParts() : self
- Loops over the $parts array from the current position, checks if the space should be added, then adds it to $retParts and returns.
- isSpaceToken() : bool
- Returns true if the passed HeaderPart is a Token instance and a space.
- parseRawValue() : array<string|int, IHeaderPart>
- Parses the raw header value into header parts.
- shouldAddSpace() : bool
- Returns true if a space should be added based on the passed last and next parts.
Properties
$consumerService
protected
ConsumerService
$consumerService
used to get consumer instances for sub-consumers.
$partFactory
protected
HeaderPartFactory
$partFactory
used to construct IHeaderPart objects
Methods
__construct()
public
__construct(ConsumerService $consumerService, HeaderPartFactory $partFactory) : mixed
Parameters
- $consumerService : ConsumerService
- $partFactory : HeaderPartFactory
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
getInstance()
Returns the singleton instance for the class.
public
static getInstance(ConsumerService $consumerService, HeaderPartFactory $partFactory) : mixed
Parameters
- $consumerService : ConsumerService
- $partFactory : HeaderPartFactory
Return values
mixed —getSubConsumers()
QuotedStringConsumer doesn't have any sub-consumers. This method returns an empty array.
public
getSubConsumers() : array<string|int, AbstractConsumer>
Return values
array<string|int, AbstractConsumer> —the sub-consumers
advanceToNextToken()
Determines if the iterator should be advanced to the next token after reading tokens or finding a start token.
protected
advanceToNextToken(Iterator $tokens, bool $isStartToken) : static
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.
Parameters
- $tokens : Iterator
-
The token iterator.
- $isStartToken : bool
-
true for the start token.
Return values
static —filterIgnoredSpaces()
No ignored spaces in a quoted part. Returns the passed $parts param as-is.
protected
filterIgnoredSpaces(array<string|int, mixed> $parts) : array<string|int, HeaderPart>
Parameters
- $parts : array<string|int, mixed>
Return values
array<string|int, HeaderPart> —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()
Constructs a LiteralPart and returns it.
protected
getPartForToken(string $token, bool $isLiteral) : IHeaderPart|null
Parameters
- $token : string
- $isLiteral : bool
-
not used - everything in a quoted string is a literal
Return values
IHeaderPart|null —getTokenParts()
Returns an array of IHeaderPart for the current token on the iterator.
protected
getTokenParts(Iterator $tokens) : array<string|int, IHeaderPart>
If the current token is a start token from a sub-consumer, the sub- consumer's AbstractConsumer::parseTokensIntoParts() method is called.
Parameters
- $tokens : Iterator
-
The token iterator.
Return values
array<string|int, IHeaderPart> —getTokenSeparators()
Returns a single regex pattern for a double quote.
protected
getTokenSeparators() : array<string|int, string>
Return values
array<string|int, string> —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()
Returns true if the token is a double quote.
protected
isEndToken(string $token) : bool
Parameters
- $token : string
-
The current token
Return values
bool —isStartToken()
Returns true if the token is a double quote.
protected
isStartToken(string $token) : bool
Parameters
- $token : string
-
The current token
Return values
bool —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
addSpaces()
Checks if the passed space part should be added to the returned parts and adds it.
private
addSpaces(array<string|int, HeaderPart> $parts, array<string|int, HeaderPart> &$retParts, int $curIndex[, HeaderPart &$spacePart = null ]) : self
Never adds a space if it's the first part, otherwise only add it if either part isn't set to ignore the space
Parameters
- $parts : array<string|int, HeaderPart>
- $retParts : array<string|int, HeaderPart>
- $curIndex : int
- $spacePart : HeaderPart = null
Return values
self —addSpaceToRetParts()
Loops over the $parts array from the current position, checks if the space should be added, then adds it to $retParts and returns.
private
addSpaceToRetParts(array<string|int, HeaderPart> $parts, array<string|int, HeaderPart> &$retParts, int $curIndex, HeaderPart &$spacePart, HeaderPart $lastPart) : self
Parameters
- $parts : array<string|int, HeaderPart>
- $retParts : array<string|int, HeaderPart>
- $curIndex : int
- $spacePart : HeaderPart
- $lastPart : HeaderPart
Return values
self —isSpaceToken()
Returns true if the passed HeaderPart is a Token instance and a space.
private
isSpaceToken(HeaderPart $part) : bool
Parameters
- $part : HeaderPart
Return values
bool —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
shouldAddSpace()
Returns true if a space should be added based on the passed last and next parts.
private
shouldAddSpace(HeaderPart $nextPart, HeaderPart $lastPart) : bool
Parameters
- $nextPart : HeaderPart
- $lastPart : HeaderPart