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\Stream; |
8
|
|
|
|
9
|
|
|
use GuzzleHttp\Psr7\LimitStream; |
10
|
|
|
use Psr\Http\Message\StreamInterface; |
11
|
|
|
use ZBateson\StreamDecorators\Base64StreamDecorator; |
12
|
|
|
use ZBateson\StreamDecorators\QuotedPrintableStreamDecorator; |
13
|
|
|
use ZBateson\StreamDecorators\UUStreamDecorator; |
14
|
|
|
use ZBateson\StreamDecorators\CharsetStreamDecorator; |
15
|
|
|
use ZBateson\MailMimeParser\Message\Part\PartBuilder; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Factory class for Psr7 stream decorators used in MailMimeParser. |
19
|
|
|
* |
20
|
|
|
* @author Zaahid Bateson |
21
|
|
|
*/ |
22
|
|
|
class StreamDecoratorFactory |
23
|
|
|
{ |
24
|
|
|
public function getLimitedPartStream(StreamInterface $stream, PartBuilder $part) |
25
|
|
|
{ |
26
|
|
|
return $this->newLimitStreamDecorator( |
27
|
|
|
$stream, |
28
|
|
|
$part->getStreamPartLength(), |
29
|
|
|
$part->getStreamPartStartOffset() |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function getLimitedContentStream(StreamInterface $stream, PartBuilder $part) |
34
|
|
|
{ |
35
|
|
|
$length = $part->getStreamContentLength(); |
36
|
|
|
if ($length !== 0) { |
37
|
|
|
return $this->newLimitStreamDecorator( |
38
|
|
|
$stream, |
39
|
|
|
$part->getStreamContentLength(), |
40
|
|
|
$part->getStreamContentStartOffset() |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
return null; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
private function newLimitStreamDecorator(StreamInterface $stream, $length, $start) |
47
|
|
|
{ |
48
|
|
|
return new LimitStream($stream, $length, $start); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function newBase64StreamDecorator(StreamInterface $stream) |
52
|
|
|
{ |
53
|
|
|
return new Base64StreamDecorator($stream); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function newQuotedPrintableStreamDecorator(StreamInterface $stream) |
57
|
|
|
{ |
58
|
|
|
return new QuotedPrintableStreamDecorator($stream); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function newUUStreamDecorator(StreamInterface $stream) |
62
|
|
|
{ |
63
|
|
|
return new UUStreamDecorator($stream); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function newCharsetStreamDecorator(StreamInterface $stream, $fromCharset, $toCharset) |
67
|
|
|
{ |
68
|
|
|
return new CharsetStreamDecorator($stream, $fromCharset, $toCharset); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|