|
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\Part; |
|
8
|
|
|
|
|
9
|
|
|
use ZBateson\MailMimeParser\Util\CharsetConverter; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Constructs and returns HeaderPart objects. |
|
13
|
|
|
* |
|
14
|
|
|
* @author Zaahid Bateson |
|
15
|
|
|
*/ |
|
16
|
|
|
class HeaderPartFactory |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var CharsetConverter $charsetConverter passed to HeaderPart constructors |
|
20
|
|
|
* for converting strings in HeaderPart::convertEncoding |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $charsetConverter; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Sets up dependencies. |
|
26
|
|
|
* |
|
27
|
|
|
* @param CharsetConverter $charsetConverter |
|
28
|
|
|
*/ |
|
29
|
10 |
|
public function __construct(CharsetConverter $charsetConverter) |
|
30
|
|
|
{ |
|
31
|
10 |
|
$this->charsetConverter = $charsetConverter; |
|
32
|
10 |
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Creates and returns a default HeaderPart for this factory, allowing |
|
36
|
|
|
* subclass factories for specialized HeaderParts. |
|
37
|
|
|
* |
|
38
|
|
|
* The default implementation returns a new Token. |
|
39
|
|
|
* |
|
40
|
|
|
* @param string $value |
|
41
|
|
|
* @return HeaderPart |
|
42
|
|
|
*/ |
|
43
|
1 |
|
public function newInstance($value) |
|
44
|
|
|
{ |
|
45
|
1 |
|
return $this->newToken($value); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Initializes and returns a new Token. |
|
50
|
|
|
* |
|
51
|
|
|
* @param string $value |
|
52
|
|
|
* @return \ZBateson\MailMimeParser\Header\Part\Token |
|
53
|
|
|
*/ |
|
54
|
2 |
|
public function newToken($value) |
|
55
|
|
|
{ |
|
56
|
2 |
|
return new Token($this->charsetConverter, $value); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Instantiates and returns a SplitParameterToken with the given name. |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $name |
|
63
|
|
|
* @return SplitParameterToken |
|
64
|
|
|
*/ |
|
65
|
1 |
|
public function newSplitParameterToken($name) |
|
66
|
|
|
{ |
|
67
|
1 |
|
return new SplitParameterToken($this->charsetConverter, $name); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Initializes and returns a new LiteralPart. |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $value |
|
74
|
|
|
* @return \ZBateson\MailMimeParser\Header\Part\LiteralPart |
|
75
|
|
|
*/ |
|
76
|
1 |
|
public function newLiteralPart($value) |
|
77
|
|
|
{ |
|
78
|
1 |
|
return new LiteralPart($this->charsetConverter, $value); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Initializes and returns a new MimeLiteralPart. |
|
83
|
|
|
* |
|
84
|
|
|
* @param string $value |
|
85
|
|
|
* @return \ZBateson\MailMimeParser\Header\Part\MimeLiteralPart |
|
86
|
|
|
*/ |
|
87
|
1 |
|
public function newMimeLiteralPart($value) |
|
88
|
|
|
{ |
|
89
|
1 |
|
return new MimeLiteralPart($this->charsetConverter, $value); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Initializes and returns a new CommentPart. |
|
94
|
|
|
* |
|
95
|
|
|
* @param string $value |
|
96
|
|
|
* @return \ZBateson\MailMimeParser\Header\Part\CommentPart |
|
97
|
|
|
*/ |
|
98
|
1 |
|
public function newCommentPart($value) |
|
99
|
|
|
{ |
|
100
|
1 |
|
return new CommentPart($this->charsetConverter, $value); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Initializes and returns a new AddressPart. |
|
105
|
|
|
* |
|
106
|
|
|
* @param string $name |
|
107
|
|
|
* @param string $email |
|
108
|
|
|
* @return \ZBateson\MailMimeParser\Header\Part\AddressPart |
|
109
|
|
|
*/ |
|
110
|
1 |
|
public function newAddressPart($name, $email) |
|
111
|
|
|
{ |
|
112
|
1 |
|
return new AddressPart($this->charsetConverter, $name, $email); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Initializes and returns a new AddressGroupPart |
|
117
|
|
|
* |
|
118
|
|
|
* @param array $addresses |
|
119
|
|
|
* @param string $name |
|
120
|
|
|
* @return \ZBateson\MailMimeParser\Header\Part\AddressGroupPart |
|
121
|
|
|
*/ |
|
122
|
1 |
|
public function newAddressGroupPart(array $addresses, $name = '') |
|
123
|
|
|
{ |
|
124
|
1 |
|
return new AddressGroupPart($this->charsetConverter, $addresses, $name); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Initializes and returns a new DatePart |
|
129
|
|
|
* |
|
130
|
|
|
* @param string $value |
|
131
|
|
|
* @return \ZBateson\MailMimeParser\Header\Part\DatePart |
|
132
|
|
|
*/ |
|
133
|
1 |
|
public function newDatePart($value) |
|
134
|
|
|
{ |
|
135
|
1 |
|
return new DatePart($this->charsetConverter, $value); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Initializes and returns a new ParameterPart. |
|
140
|
|
|
* |
|
141
|
|
|
* @param string $name |
|
142
|
|
|
* @param string $value |
|
143
|
|
|
* @param string $language |
|
144
|
|
|
* @return \ZBateson\MailMimeParser\Header\Part\ParameterPart |
|
145
|
|
|
*/ |
|
146
|
1 |
|
public function newParameterPart($name, $value, $language = null) |
|
147
|
|
|
{ |
|
148
|
1 |
|
return new ParameterPart($this->charsetConverter, $name, $value, $language); |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|