|
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\Parser\Proxy; |
|
9
|
|
|
|
|
10
|
|
|
use Psr\Log\LoggerInterface; |
|
11
|
|
|
use ZBateson\MailMimeParser\Message\Factory\PartHeaderContainerFactory; |
|
12
|
|
|
use ZBateson\MailMimeParser\Message\MimePart; |
|
13
|
|
|
use ZBateson\MailMimeParser\Parser\IParserService; |
|
14
|
|
|
use ZBateson\MailMimeParser\Parser\Part\ParserPartChildrenContainerFactory; |
|
15
|
|
|
use ZBateson\MailMimeParser\Parser\Part\ParserPartStreamContainerFactory; |
|
16
|
|
|
use ZBateson\MailMimeParser\Parser\PartBuilder; |
|
17
|
|
|
use ZBateson\MailMimeParser\Stream\StreamFactory; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Responsible for creating proxied IMimePart instances wrapped in a |
|
21
|
|
|
* ParserMimePartProxy with a MimeParser. |
|
22
|
|
|
* |
|
23
|
|
|
* @author Zaahid Bateson |
|
24
|
|
|
*/ |
|
25
|
|
|
class ParserMimePartProxyFactory extends ParserPartProxyFactory |
|
26
|
|
|
{ |
|
27
|
|
|
protected LoggerInterface $logger; |
|
28
|
|
|
|
|
29
|
|
|
protected StreamFactory $streamFactory; |
|
30
|
|
|
|
|
31
|
|
|
protected ParserPartStreamContainerFactory $parserPartStreamContainerFactory; |
|
32
|
|
|
|
|
33
|
|
|
protected PartHeaderContainerFactory $partHeaderContainerFactory; |
|
34
|
|
|
|
|
35
|
|
|
protected ParserPartChildrenContainerFactory $parserPartChildrenContainerFactory; |
|
36
|
|
|
|
|
37
|
3 |
|
public function __construct( |
|
38
|
|
|
LoggerInterface $logger, |
|
39
|
|
|
StreamFactory $sdf, |
|
40
|
|
|
PartHeaderContainerFactory $phcf, |
|
41
|
|
|
ParserPartStreamContainerFactory $pscf, |
|
42
|
|
|
ParserPartChildrenContainerFactory $ppccf |
|
43
|
|
|
) { |
|
44
|
3 |
|
$this->logger = $logger; |
|
45
|
3 |
|
$this->streamFactory = $sdf; |
|
46
|
3 |
|
$this->partHeaderContainerFactory = $phcf; |
|
47
|
3 |
|
$this->parserPartStreamContainerFactory = $pscf; |
|
48
|
3 |
|
$this->parserPartChildrenContainerFactory = $ppccf; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Constructs a new ParserMimePartProxy wrapping an IMimePart object that |
|
53
|
|
|
* will dynamically parse a message's content and parts as they're |
|
54
|
|
|
* requested. |
|
55
|
|
|
*/ |
|
56
|
74 |
|
public function newInstance(PartBuilder $partBuilder, IParserService $parser) : ParserMimePartProxy |
|
57
|
|
|
{ |
|
58
|
74 |
|
$parserProxy = new ParserMimePartProxy($partBuilder, $parser); |
|
59
|
|
|
|
|
60
|
74 |
|
$streamContainer = $this->parserPartStreamContainerFactory->newInstance($parserProxy); |
|
61
|
74 |
|
$headerContainer = $this->partHeaderContainerFactory->newInstance($parserProxy->getHeaderContainer()); |
|
62
|
74 |
|
$childrenContainer = $this->parserPartChildrenContainerFactory->newInstance($parserProxy); |
|
63
|
|
|
|
|
64
|
74 |
|
$part = new MimePart( |
|
65
|
74 |
|
$partBuilder->getParent()->getPart(), |
|
66
|
74 |
|
$this->logger, |
|
67
|
74 |
|
$streamContainer, |
|
68
|
74 |
|
$headerContainer, |
|
69
|
74 |
|
$childrenContainer |
|
70
|
74 |
|
); |
|
71
|
74 |
|
$parserProxy->setPart($part); |
|
72
|
|
|
|
|
73
|
74 |
|
$streamContainer->setStream($this->streamFactory->newMessagePartStream($part)); |
|
74
|
74 |
|
$part->attach($streamContainer); |
|
75
|
74 |
|
return $parserProxy; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|