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. |
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
|
|
|
public function __construct( |
47
|
|
|
StreamFactory $sdf, |
48
|
|
|
PartHeaderContainerFactory $phcf, |
49
|
|
|
ParserPartStreamContainerFactory $pscf, |
50
|
|
|
ParserPartChildrenContainerFactory $ppccf |
51
|
|
|
) { |
52
|
|
|
$this->streamFactory = $sdf; |
53
|
|
|
$this->partHeaderContainerFactory = $phcf; |
54
|
|
|
$this->parserPartStreamContainerFactory = $pscf; |
55
|
|
|
$this->parserPartChildrenContainerFactory = $ppccf; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Constructs a new ParserMimePartProxy wrapping an IMimePart object |
60
|
|
|
* |
61
|
|
|
* @param PartBuilder $partBuilder |
62
|
|
|
* @param PartHeaderContainer $headerContainer |
63
|
|
|
* @param ParserMimePartProxy $parent |
64
|
|
|
* @return ParserMimePartProxy |
65
|
|
|
*/ |
66
|
|
|
public function newInstance(PartBuilder $partBuilder, IParser $parser) |
67
|
|
|
{ |
68
|
|
|
$parserProxy = new ParserMimePartProxy($partBuilder, $parser); |
69
|
|
|
|
70
|
|
|
$streamContainer = $this->parserPartStreamContainerFactory->newInstance($parserProxy); |
71
|
|
|
$headerContainer = $this->partHeaderContainerFactory->newInstance($parserProxy->getHeaderContainer()); |
72
|
|
|
$childrenContainer = $this->parserPartChildrenContainerFactory->newInstance($parserProxy); |
73
|
|
|
|
74
|
|
|
$part = new MimePart( |
75
|
|
|
$partBuilder->getParent()->getPart(), |
76
|
|
|
$streamContainer, |
77
|
|
|
$headerContainer, |
78
|
|
|
$childrenContainer |
79
|
|
|
); |
80
|
|
|
$parserProxy->setPart($part); |
81
|
|
|
|
82
|
|
|
$streamContainer->setStream($this->streamFactory->newMessagePartStream($part)); |
83
|
|
|
$part->attach($streamContainer); |
84
|
|
|
return $parserProxy; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|