|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the ZBateson\MailMimeParser project. |
|
4
|
|
|
* |
|
5
|
|
|
* @license http://opensource.org/licenses/bsd-license.php BSD |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace ZBateson\MailMimeParser\Header\Consumer; |
|
9
|
|
|
|
|
10
|
|
|
use Iterator; |
|
11
|
|
|
use Psr\Log\LoggerInterface; |
|
12
|
|
|
use ZBateson\MailMimeParser\Header\IHeaderPart; |
|
13
|
|
|
use ZBateson\MailMimeParser\Header\Part\HeaderPartFactory; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Serves as a base-consumer for recipient/sender email address headers (like |
|
17
|
|
|
* From and To). |
|
18
|
|
|
* |
|
19
|
|
|
* AddressBaseConsumerService passes on token processing to its sub-consumer, an |
|
20
|
|
|
* AddressConsumerService, and collects Part\AddressPart objects processed and |
|
21
|
|
|
* returned by AddressConsumerService. |
|
22
|
|
|
* |
|
23
|
|
|
* @author Zaahid Bateson |
|
24
|
|
|
*/ |
|
25
|
|
|
class AddressBaseConsumerService extends AbstractConsumerService |
|
26
|
|
|
{ |
|
27
|
5 |
|
public function __construct( |
|
28
|
|
|
LoggerInterface $logger, |
|
29
|
|
|
HeaderPartFactory $partFactory, |
|
30
|
|
|
AddressConsumerService $addressConsumerService |
|
31
|
|
|
) { |
|
32
|
5 |
|
parent::__construct($logger, $partFactory, [$addressConsumerService]); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Returns an empty array. |
|
37
|
|
|
* |
|
38
|
|
|
* @return string[] an array of regex pattern matchers |
|
39
|
|
|
*/ |
|
40
|
5 |
|
protected function getTokenSeparators() : array |
|
41
|
|
|
{ |
|
42
|
5 |
|
return []; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Disables advancing for start tokens. |
|
47
|
|
|
* |
|
48
|
|
|
* The start token for AddressBaseConsumerService is part of an |
|
49
|
|
|
* {@see AddressPart} (or a sub-consumer) and so must be passed on. |
|
50
|
|
|
*/ |
|
51
|
100 |
|
protected function advanceToNextToken(Iterator $tokens, bool $isStartToken) : static |
|
52
|
|
|
{ |
|
53
|
100 |
|
if ($isStartToken) { |
|
54
|
100 |
|
return $this; |
|
55
|
|
|
} |
|
56
|
100 |
|
parent::advanceToNextToken($tokens, $isStartToken); |
|
57
|
100 |
|
return $this; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* AddressBaseConsumerService doesn't have start/end tokens, and so always |
|
62
|
|
|
* returns false. |
|
63
|
|
|
* |
|
64
|
|
|
* @return false |
|
65
|
|
|
*/ |
|
66
|
100 |
|
protected function isEndToken(string $token) : bool |
|
67
|
|
|
{ |
|
68
|
100 |
|
return false; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* AddressBaseConsumerService doesn't have start/end tokens, and so always |
|
73
|
|
|
* returns false. |
|
74
|
|
|
* |
|
75
|
|
|
* @codeCoverageIgnore |
|
76
|
|
|
* @return false |
|
77
|
|
|
*/ |
|
78
|
|
|
protected function isStartToken(string $token) : bool |
|
79
|
|
|
{ |
|
80
|
|
|
return false; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Overridden so tokens aren't handled at this level, and instead are passed |
|
85
|
|
|
* on to AddressConsumerService. |
|
86
|
|
|
* |
|
87
|
|
|
* @return \ZBateson\MailMimeParser\Header\IHeaderPart[]|array |
|
88
|
|
|
*/ |
|
89
|
100 |
|
protected function getTokenParts(Iterator $tokens) : array |
|
90
|
|
|
{ |
|
91
|
100 |
|
return $this->getConsumerTokenParts($tokens); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Never reached by AddressBaseConsumerService. Overridden to satisfy |
|
96
|
|
|
* AbstractConsumerService. |
|
97
|
|
|
* |
|
98
|
|
|
* @codeCoverageIgnore |
|
99
|
|
|
*/ |
|
100
|
|
|
protected function getPartForToken(string $token, bool $isLiteral) : ?IHeaderPart |
|
101
|
|
|
{ |
|
102
|
|
|
return null; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|