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