|
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; |
|
8
|
|
|
|
|
9
|
|
|
use ZBateson\MailMimeParser\Header\Consumer\ConsumerService; |
|
10
|
|
|
use ZBateson\MailMimeParser\Header\HeaderFactory; |
|
11
|
|
|
use ZBateson\MailMimeParser\Header\Part\HeaderPartFactory; |
|
12
|
|
|
use ZBateson\MailMimeParser\Header\Part\MimeLiteralPartFactory; |
|
13
|
|
|
use ZBateson\MailMimeParser\Message\Helper\MessageHelperService; |
|
14
|
|
|
use ZBateson\MailMimeParser\Message\MessageParser; |
|
15
|
|
|
use ZBateson\MailMimeParser\Message\Part\Factory\PartBuilderFactory; |
|
16
|
|
|
use ZBateson\MailMimeParser\Message\Part\Factory\PartFactoryService; |
|
17
|
|
|
use ZBateson\MailMimeParser\Message\Part\Factory\PartStreamFilterManagerFactory; |
|
18
|
|
|
use ZBateson\StreamDecorators\Util\CharsetConverter; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Dependency injection container for use by ZBateson\MailMimeParser - because a |
|
22
|
|
|
* more complex one seems like overkill. |
|
23
|
|
|
* |
|
24
|
|
|
* Constructs objects and whatever dependencies they require. |
|
25
|
|
|
* |
|
26
|
|
|
* @author Zaahid Bateson |
|
27
|
|
|
*/ |
|
28
|
|
|
class SimpleDi |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var type |
|
|
|
|
|
|
32
|
|
|
*/ |
|
33
|
|
|
protected $partBuilderFactory; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var type |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $partFactoryService; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var type |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $partFilterFactory; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var type |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $partStreamFilterManagerFactory; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var \ZBateson\MailMimeParser\Header\HeaderFactory singleton 'service' |
|
52
|
|
|
* instance |
|
53
|
|
|
*/ |
|
54
|
|
|
protected $headerFactory; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @var \ZBateson\MailMimeParser\Header\Part\HeaderPartFactory singleton |
|
58
|
|
|
* 'service' instance |
|
59
|
|
|
*/ |
|
60
|
|
|
protected $headerPartFactory; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @var \ZBateson\MailMimeParser\Header\Part\MimeLiteralPartFactory |
|
64
|
|
|
* singleton 'service' instance |
|
65
|
|
|
*/ |
|
66
|
|
|
protected $mimeLiteralPartFactory; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @var \ZBateson\MailMimeParser\Header\Consumer\ConsumerService singleton |
|
70
|
|
|
* 'service' instance |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $consumerService; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @var MessageHelperService Used to get MessageHelper singletons |
|
76
|
|
|
*/ |
|
77
|
|
|
protected $messageHelperService; |
|
78
|
|
|
|
|
79
|
|
|
protected $streamFactory; |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Constructs a SimpleDi - call singleton() to invoke |
|
83
|
|
|
*/ |
|
84
|
|
|
private function __construct() |
|
85
|
1 |
|
{ |
|
86
|
|
|
} |
|
87
|
1 |
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Returns the singleton instance. |
|
90
|
|
|
* |
|
91
|
|
|
* @return \ZBateson\MailMimeParser\SimpleDi |
|
92
|
|
|
*/ |
|
93
|
|
|
public static function singleton() |
|
94
|
7 |
|
{ |
|
95
|
|
|
static $singleton = null; |
|
96
|
7 |
|
if ($singleton === null) { |
|
97
|
7 |
|
$singleton = new SimpleDi(); |
|
98
|
1 |
|
} |
|
99
|
|
|
return $singleton; |
|
100
|
7 |
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Returns a singleton 'service' instance for the given service named $var |
|
104
|
|
|
* with a class type of $class. |
|
105
|
|
|
* |
|
106
|
|
|
* @param string $var the name of the service |
|
107
|
|
|
* @param string $class the name of the class |
|
108
|
|
|
* @return mixed the service object |
|
109
|
|
|
*/ |
|
110
|
|
|
protected function getInstance($var, $class) |
|
111
|
1 |
|
{ |
|
112
|
|
|
if ($this->$var === null) { |
|
113
|
1 |
|
$this->$var = new $class(); |
|
114
|
1 |
|
} |
|
115
|
|
|
return $this->$var; |
|
116
|
1 |
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Constructs and returns a new MessageParser object. |
|
120
|
|
|
* |
|
121
|
|
|
* @return \ZBateson\MailMimeParser\Message\MessageParser |
|
122
|
|
|
*/ |
|
123
|
|
|
public function newMessageParser() |
|
124
|
1 |
|
{ |
|
125
|
|
|
return new MessageParser( |
|
126
|
1 |
|
$this->getPartFactoryService(), |
|
127
|
1 |
|
$this->getPartBuilderFactory() |
|
128
|
1 |
|
); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Returns a MessageHelperService instance. |
|
133
|
|
|
* |
|
134
|
|
|
* @return MessageHelperService |
|
135
|
|
|
*/ |
|
136
|
|
|
public function getMessageHelperService() |
|
137
|
|
|
{ |
|
138
|
|
|
if ($this->messageHelperService === null) { |
|
139
|
|
|
$this->messageHelperService = new MessageHelperService( |
|
140
|
|
|
$this->getPartBuilderFactory() |
|
141
|
|
|
); |
|
142
|
|
|
$this->messageHelperService->setPartFactoryService( |
|
143
|
|
|
$this->getPartFactoryService() |
|
144
|
|
|
); |
|
145
|
1 |
|
} |
|
146
|
|
|
return $this->messageHelperService; |
|
147
|
1 |
|
} |
|
148
|
1 |
|
|
|
149
|
1 |
|
public function getPartFilterFactory() |
|
150
|
|
|
{ |
|
151
|
|
|
return $this->getInstance( |
|
152
|
|
|
'partFilterFactory', |
|
153
|
|
|
__NAMESPACE__ . '\Message\PartFilterFactory' |
|
154
|
|
|
); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
1 |
|
/** |
|
158
|
|
|
* |
|
159
|
1 |
|
* @return type |
|
160
|
1 |
|
*/ |
|
161
|
1 |
|
public function getPartFactoryService() |
|
162
|
1 |
|
{ |
|
163
|
1 |
|
if ($this->partFactoryService === null) { |
|
164
|
1 |
|
$this->partFactoryService = new PartFactoryService( |
|
|
|
|
|
|
165
|
|
|
$this->getHeaderFactory(), |
|
166
|
|
|
$this->getPartFilterFactory(), |
|
167
|
1 |
|
$this->getStreamFactory(), |
|
168
|
|
|
$this->getPartStreamFilterManagerFactory(), |
|
169
|
|
|
$this->getMessageHelperService() |
|
170
|
1 |
|
); |
|
171
|
|
|
} |
|
172
|
1 |
|
return $this->partFactoryService; |
|
173
|
1 |
|
} |
|
174
|
1 |
|
|
|
175
|
|
|
public function getPartBuilderFactory() |
|
176
|
|
|
{ |
|
177
|
1 |
|
if ($this->partBuilderFactory === null) { |
|
178
|
|
|
$this->partBuilderFactory = new PartBuilderFactory( |
|
|
|
|
|
|
179
|
|
|
$this->getHeaderFactory() |
|
180
|
|
|
); |
|
181
|
|
|
} |
|
182
|
|
|
return $this->partBuilderFactory; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
2 |
|
/** |
|
186
|
|
|
* Returns the header factory service instance. |
|
187
|
2 |
|
* |
|
188
|
1 |
|
* @return \ZBateson\MailMimeParser\Header\HeaderFactory |
|
189
|
|
|
*/ |
|
190
|
2 |
|
public function getHeaderFactory() |
|
191
|
|
|
{ |
|
192
|
|
|
if ($this->headerFactory === null) { |
|
193
|
1 |
|
$this->headerFactory = new HeaderFactory($this->getConsumerService()); |
|
194
|
|
|
} |
|
195
|
1 |
|
return $this->headerFactory; |
|
196
|
1 |
|
} |
|
197
|
1 |
|
|
|
198
|
|
|
public function getStreamFactory() |
|
199
|
|
|
{ |
|
200
|
|
|
return $this->getInstance( |
|
201
|
1 |
|
'streamFactory', |
|
202
|
|
|
__NAMESPACE__ . '\Stream\StreamFactory' |
|
203
|
1 |
|
); |
|
204
|
1 |
|
} |
|
205
|
1 |
|
|
|
206
|
|
|
public function getPartStreamFilterManagerFactory() |
|
207
|
|
|
{ |
|
208
|
1 |
|
if ($this->partStreamFilterManagerFactory === null) { |
|
209
|
1 |
|
$this->partStreamFilterManagerFactory = new PartStreamFilterManagerFactory( |
|
|
|
|
|
|
210
|
1 |
|
$this->getStreamFactory() |
|
211
|
|
|
); |
|
212
|
|
|
} |
|
213
|
|
|
return $this->getInstance( |
|
214
|
2 |
|
'partStreamFilterManagerFactory', |
|
215
|
|
|
__NAMESPACE__ . '\Message\Part\PartStreamFilterManagerFactory' |
|
216
|
2 |
|
); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
public function getCharsetConverter() |
|
220
|
|
|
{ |
|
221
|
|
|
return new CharsetConverter(); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
2 |
|
/** |
|
225
|
|
|
* Returns the part factory service |
|
226
|
2 |
|
* |
|
227
|
1 |
|
* @return \ZBateson\MailMimeParser\Header\Part\HeaderPartFactory |
|
228
|
|
|
*/ |
|
229
|
2 |
|
public function getHeaderPartFactory() |
|
230
|
|
|
{ |
|
231
|
|
|
if ($this->headerPartFactory === null) { |
|
232
|
|
|
$this->headerPartFactory = new HeaderPartFactory($this->getCharsetConverter()); |
|
233
|
|
|
} |
|
234
|
|
|
return $this->headerPartFactory; |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
2 |
|
/** |
|
238
|
|
|
* Returns the MimeLiteralPartFactory service |
|
239
|
2 |
|
* |
|
240
|
1 |
|
* @return \ZBateson\MailMimeParser\Header\Part\MimeLiteralPartFactory |
|
241
|
|
|
*/ |
|
242
|
2 |
|
public function getMimeLiteralPartFactory() |
|
243
|
|
|
{ |
|
244
|
|
|
if ($this->mimeLiteralPartFactory === null) { |
|
245
|
|
|
$this->mimeLiteralPartFactory = new MimeLiteralPartFactory($this->getCharsetConverter()); |
|
246
|
|
|
} |
|
247
|
|
|
return $this->mimeLiteralPartFactory; |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
2 |
|
/** |
|
251
|
|
|
* Returns the header consumer service |
|
252
|
2 |
|
* |
|
253
|
1 |
|
* @return \ZBateson\MailMimeParser\Header\Consumer\ConsumerService |
|
254
|
1 |
|
*/ |
|
255
|
1 |
|
public function getConsumerService() |
|
256
|
|
|
{ |
|
257
|
|
|
if ($this->consumerService === null) { |
|
258
|
2 |
|
$this->consumerService = new ConsumerService( |
|
259
|
|
|
$this->getHeaderPartFactory(), |
|
260
|
|
|
$this->getMimeLiteralPartFactory() |
|
261
|
|
|
); |
|
262
|
|
|
} |
|
263
|
|
|
return $this->consumerService; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
} |
|
267
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths