<?php
namespace ZBateson\MailMimeParser\Header\Consumer;
use Iterator;
use Psr\Log\LoggerInterface;
use ZBateson\MailMimeParser\Header\Consumer\Received\DomainConsumerService;
use ZBateson\MailMimeParser\Header\Consumer\Received\GenericReceivedConsumerService;
use ZBateson\MailMimeParser\Header\Consumer\Received\ReceivedDateConsumerService;
use ZBateson\MailMimeParser\Header\Part\HeaderPartFactory;
use ZBateson\MailMimeParser\Header\Part\Token;
class ReceivedConsumerService extends AbstractConsumerService
{
public function __construct(
LoggerInterface $logger,
HeaderPartFactory $partFactory,
DomainConsumerService $fromDomainConsumerService,
DomainConsumerService $byDomainConsumerService,
GenericReceivedConsumerService $viaGenericReceivedConsumerService,
GenericReceivedConsumerService $withGenericReceivedConsumerService,
GenericReceivedConsumerService $idGenericReceivedConsumerService,
GenericReceivedConsumerService $forGenericReceivedConsumerService,
ReceivedDateConsumerService $receivedDateConsumerService,
CommentConsumerService $commentConsumerService
) {
parent::__construct(
$logger,
$partFactory,
[
$fromDomainConsumerService,
$byDomainConsumerService,
$viaGenericReceivedConsumerService,
$withGenericReceivedConsumerService,
$idGenericReceivedConsumerService,
$forGenericReceivedConsumerService,
$receivedDateConsumerService,
$commentConsumerService
]
);
}
protected function getTokenSeparators() : array
{
return [];
}
protected function isEndToken(string $token) : bool
{
return false;
}
protected function isStartToken(string $token) : bool
{
return false;
}
protected function getTokenSplitPattern() : string
{
$sChars = \implode('|', $this->getAllTokenSeparators());
return '~(' . $sChars . ')~';
}
protected function advanceToNextToken(Iterator $tokens, bool $isStartToken) : static
{
if ($isStartToken) {
$tokens->next();
} elseif ($tokens->valid() && !$this->isEndToken($tokens->current())) {
foreach ($this->subConsumers as $consumer) {
if ($consumer->isStartToken($tokens->current())) {
return $this;
}
}
$tokens->next();
}
return $this;
}
protected function processParts(array $parts) : array
{
return \array_values(\array_filter($parts, fn ($p) => !$p instanceof Token));
}
}