Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <fabien@symfony.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
 
12
namespace Symfony\Component\Mime\Part;
13
 
14
use Symfony\Component\Mime\Header\Headers;
15
 
16
/**
17
 * @author Sebastiaan Stok <s.stok@rollerscapes.net>
18
 */
19
class SMimePart extends AbstractPart
20
{
21
    /** @internal */
22
    protected $_headers;
23
 
24
    private $body;
25
    private $type;
26
    private $subtype;
27
    private $parameters;
28
 
29
    public function __construct(iterable|string $body, string $type, string $subtype, array $parameters)
30
    {
31
        unset($this->_headers);
32
 
33
        parent::__construct();
34
 
35
        $this->body = $body;
36
        $this->type = $type;
37
        $this->subtype = $subtype;
38
        $this->parameters = $parameters;
39
    }
40
 
41
    public function getMediaType(): string
42
    {
43
        return $this->type;
44
    }
45
 
46
    public function getMediaSubtype(): string
47
    {
48
        return $this->subtype;
49
    }
50
 
51
    public function bodyToString(): string
52
    {
53
        if (\is_string($this->body)) {
54
            return $this->body;
55
        }
56
 
57
        $body = '';
58
        foreach ($this->body as $chunk) {
59
            $body .= $chunk;
60
        }
61
        $this->body = $body;
62
 
63
        return $body;
64
    }
65
 
66
    public function bodyToIterable(): iterable
67
    {
68
        if (\is_string($this->body)) {
69
            yield $this->body;
70
 
71
            return;
72
        }
73
 
74
        $body = '';
75
        foreach ($this->body as $chunk) {
76
            $body .= $chunk;
77
            yield $chunk;
78
        }
79
        $this->body = $body;
80
    }
81
 
82
    public function getPreparedHeaders(): Headers
83
    {
84
        $headers = clone parent::getHeaders();
85
 
86
        $headers->setHeaderBody('Parameterized', 'Content-Type', $this->getMediaType().'/'.$this->getMediaSubtype());
87
 
88
        foreach ($this->parameters as $name => $value) {
89
            $headers->setHeaderParameter('Content-Type', $name, $value);
90
        }
91
 
92
        return $headers;
93
    }
94
 
95
    public function __sleep(): array
96
    {
97
        // convert iterables to strings for serialization
98
        if (is_iterable($this->body)) {
99
            $this->body = $this->bodyToString();
100
        }
101
 
102
        $this->_headers = $this->getHeaders();
103
 
104
        return ['_headers', 'body', 'type', 'subtype', 'parameters'];
105
    }
106
 
107
    public function __wakeup(): void
108
    {
109
        $r = new \ReflectionProperty(AbstractPart::class, 'headers');
110
        $r->setValue($this, $this->_headers);
111
        unset($this->_headers);
112
    }
113
}