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\Message\Part\Factory; |
8
|
|
|
|
9
|
|
|
use Psr\Http\Message\StreamInterface; |
10
|
|
|
use ZBateson\MailMimeParser\Stream\StreamDecoratorFactory; |
11
|
|
|
use ZBateson\MailMimeParser\Header\HeaderFactory; |
12
|
|
|
use ZBateson\MailMimeParser\Message\PartFilterFactory; |
13
|
|
|
use ZBateson\MailMimeParser\Message\Part\MimePart; |
14
|
|
|
use ZBateson\MailMimeParser\Message\Part\PartBuilder; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Responsible for creating MimePart instances. |
18
|
|
|
* |
19
|
|
|
* @author Zaahid Bateson |
20
|
|
|
*/ |
21
|
|
|
class MimePartFactory extends MessagePartFactory |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var HeaderFactory an instance used for creating MimePart objects |
25
|
|
|
*/ |
26
|
|
|
protected $headerFactory; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var PartFilterFactory an instance used for creating MimePart objects |
30
|
|
|
*/ |
31
|
|
|
protected $partFilterFactory; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Initializes dependencies. |
35
|
|
|
* |
36
|
|
|
* @param StreamDecoratorFactory $sdf |
37
|
|
|
* @param PartStreamFilterManagerFactory $psf |
38
|
|
|
* @param HeaderFactory $hf |
39
|
|
|
* @param PartFilterFactory $pf |
40
|
|
|
*/ |
41
|
1 |
|
public function __construct( |
42
|
|
|
StreamDecoratorFactory $sdf, |
43
|
|
|
PartStreamFilterManagerFactory $psf, |
44
|
|
|
HeaderFactory $hf, |
45
|
|
|
PartFilterFactory $pf |
46
|
|
|
) { |
47
|
1 |
|
parent::__construct($sdf, $psf); |
48
|
1 |
|
$this->headerFactory = $hf; |
49
|
1 |
|
$this->partFilterFactory = $pf; |
50
|
1 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Returns the singleton instance for the class. |
54
|
|
|
* |
55
|
|
|
* @param StreamDecoratorFactory $sdf |
56
|
|
|
* @param PartStreamFilterManagerFactory $psf |
57
|
|
|
* @param HeaderFactory $hf |
58
|
|
|
* @param PartFilterFactory $pf |
59
|
|
|
* @return MessagePartFactory |
60
|
|
|
*/ |
61
|
|
|
public static function getInstance( |
62
|
|
|
StreamDecoratorFactory $sdf, |
63
|
|
|
PartStreamFilterManagerFactory $psf, |
64
|
|
|
HeaderFactory $hf = null, |
65
|
|
|
PartFilterFactory $pf = null |
66
|
|
|
) { |
67
|
|
|
$instance = static::getCachedInstance(); |
68
|
|
|
if ($instance === null) { |
69
|
|
|
$instance = new static($sdf, $psf, $hf, $pf); |
|
|
|
|
70
|
|
|
static::setCachedInstance($instance); |
71
|
|
|
} |
72
|
|
|
return $instance; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Constructs a new MimePart object and returns it |
77
|
|
|
* |
78
|
|
|
* @param StreamInterface $messageStream |
79
|
|
|
* @param PartBuilder $partBuilder |
80
|
|
|
* @return \ZBateson\MailMimeParser\Message\Part\MimePart |
81
|
|
|
*/ |
82
|
1 |
|
public function newInstance(StreamInterface $messageStream, PartBuilder $partBuilder) |
83
|
|
|
{ |
84
|
1 |
|
return new MimePart( |
85
|
1 |
|
$this->headerFactory, |
86
|
1 |
|
$this->partFilterFactory, |
87
|
1 |
|
$partBuilder, |
88
|
1 |
|
$this->partStreamFilterManagerFactory->newInstance(), |
89
|
1 |
|
$this->streamDecoratorFactory->getLimitedPartStream($messageStream, $partBuilder), |
90
|
1 |
|
$this->streamDecoratorFactory->getLimitedContentStream($messageStream, $partBuilder) |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|