|
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
|
|
|
namespace ZBateson\MailMimeParser\Header\Consumer; |
|
8
|
|
|
|
|
9
|
|
|
use Iterator; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Serves as a base-consumer for recipient/sender email address headers (like |
|
13
|
|
|
* From and To). |
|
14
|
|
|
* |
|
15
|
|
|
* AddressBaseConsumer passes on token processing to its sub-consumer, an |
|
16
|
|
|
* AddressConsumer, and collects Part\AddressPart objects processed and returned |
|
17
|
|
|
* by AddressConsumer. |
|
18
|
|
|
* |
|
19
|
|
|
* @author Zaahid Bateson |
|
20
|
|
|
*/ |
|
21
|
|
|
class AddressBaseConsumer extends AbstractConsumer |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Returns \ZBateson\MailMimeParser\Header\Consumer\AddressConsumer as a |
|
25
|
|
|
* sub-consumer. |
|
26
|
|
|
* |
|
27
|
|
|
* @return AbstractConsumer[] the sub-consumers |
|
28
|
|
|
*/ |
|
29
|
3 |
|
protected function getSubConsumers() |
|
30
|
|
|
{ |
|
31
|
|
|
return [ |
|
32
|
3 |
|
$this->consumerService->getAddressConsumer() |
|
33
|
|
|
]; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Returns an empty array. |
|
38
|
|
|
* |
|
39
|
|
|
* @return string[] an array of regex pattern matchers |
|
40
|
|
|
*/ |
|
41
|
3 |
|
protected function getTokenSeparators() |
|
42
|
|
|
{ |
|
43
|
3 |
|
return []; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Disables advancing for start tokens. |
|
48
|
|
|
* |
|
49
|
|
|
* The start token for AddressBaseConsumer is part of an AddressPart (or a |
|
50
|
|
|
* sub-consumer) and so must be passed on. |
|
51
|
|
|
* |
|
52
|
|
|
* @param Iterator $tokens |
|
53
|
|
|
* @param bool $isStartToken |
|
54
|
|
|
*/ |
|
55
|
3 |
|
protected function advanceToNextToken(Iterator $tokens, $isStartToken) |
|
56
|
|
|
{ |
|
57
|
3 |
|
if ($isStartToken) { |
|
58
|
3 |
|
return; |
|
59
|
|
|
} |
|
60
|
3 |
|
parent::advanceToNextToken($tokens, $isStartToken); |
|
61
|
3 |
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* AddressBaseConsumer doesn't have start/end tokens, and so always returns |
|
65
|
|
|
* false. |
|
66
|
|
|
* |
|
67
|
|
|
* @param string $token |
|
68
|
|
|
* @return boolean false |
|
69
|
|
|
*/ |
|
70
|
3 |
|
protected function isEndToken($token) |
|
71
|
|
|
{ |
|
72
|
3 |
|
return false; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* AddressBaseConsumer doesn't have start/end tokens, and so always returns |
|
77
|
|
|
* false. |
|
78
|
|
|
* |
|
79
|
|
|
* @codeCoverageIgnore |
|
80
|
|
|
* @param string $token |
|
81
|
|
|
* @return boolean false |
|
82
|
|
|
*/ |
|
83
|
|
|
protected function isStartToken($token) |
|
84
|
|
|
{ |
|
85
|
|
|
return false; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Overridden so tokens aren't handled at this level, and instead are passed |
|
90
|
|
|
* on to AddressConsumer. |
|
91
|
|
|
* |
|
92
|
|
|
* @param Iterator $tokens |
|
93
|
|
|
* @return \ZBateson\MailMimeParser\Header\Part\HeaderPart[]|array |
|
94
|
|
|
*/ |
|
95
|
3 |
|
protected function getTokenParts(Iterator $tokens) |
|
96
|
|
|
{ |
|
97
|
3 |
|
return $this->getConsumerTokenParts($tokens); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Never reached by AddressBaseConsumer. Overridden to satisfy |
|
102
|
|
|
* AbstractConsumer. |
|
103
|
|
|
* |
|
104
|
|
|
* @codeCoverageIgnore |
|
105
|
|
|
* @param string $token the token |
|
106
|
|
|
* @param bool $isLiteral set to true if the token represents a literal - |
|
107
|
|
|
* e.g. an escaped token |
|
108
|
|
|
* @return \ZBateson\MailMimeParser\Header\Part\HeaderPart the constructed |
|
109
|
|
|
* header part or null if the token should be ignored |
|
110
|
|
|
*/ |
|
111
|
|
|
protected function getPartForToken($token, $isLiteral) |
|
112
|
|
|
{ |
|
113
|
|
|
return null; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|