PluginProbe
WPIDE – File Manager & Code Editor / 3.5.9
WPIDE – File Manager & Code Editor v3.5.9
3.5.9 3.5.8 3.5.7 2.0.14 2.0.15 2.0.16 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.2 2.3 2.3.1 2.3.2 2.4.0 2.5 2.6 3.0 3.1 3.2 3.3 All 55 releases
wpide / vendor / symfony / mime / Part / SMimePart.php

SMimePart.php in WPIDE – File Manager & Code Editor 3.5.9, at vendor/symfony/mime/Part/SMimePart.php

122 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 /**
30 * @param iterable|string $body
31 */
32 public function __construct($body, string $type, string $subtype, array $parameters)
33 {
34 unset($this->_headers);
35
36 parent::__construct();
37
38 if (!\is_string($body) && !is_iterable($body)) {
39 throw new \TypeError(sprintf('The body of "%s" must be a string or a iterable (got "%s").', self::class, get_debug_type($body)));
40 }
41
42 $this->body = $body;
43 $this->type = $type;
44 $this->subtype = $subtype;
45 $this->parameters = $parameters;
46 }
47
48 public function getMediaType(): string
49 {
50 return $this->type;
51 }
52
53 public function getMediaSubtype(): string
54 {
55 return $this->subtype;
56 }
57
58 public function bodyToString(): string
59 {
60 if (\is_string($this->body)) {
61 return $this->body;
62 }
63
64 $body = '';
65 foreach ($this->body as $chunk) {
66 $body .= $chunk;
67 }
68 $this->body = $body;
69
70 return $body;
71 }
72
73 public function bodyToIterable(): iterable
74 {
75 if (\is_string($this->body)) {
76 yield $this->body;
77
78 return;
79 }
80
81 $body = '';
82 foreach ($this->body as $chunk) {
83 $body .= $chunk;
84 yield $chunk;
85 }
86 $this->body = $body;
87 }
88
89 public function getPreparedHeaders(): Headers
90 {
91 $headers = clone parent::getHeaders();
92
93 $headers->setHeaderBody('Parameterized', 'Content-Type', $this->getMediaType().'/'.$this->getMediaSubtype());
94
95 foreach ($this->parameters as $name => $value) {
96 $headers->setHeaderParameter('Content-Type', $name, $value);
97 }
98
99 return $headers;
100 }
101
102 public function __sleep(): array
103 {
104 // convert iterables to strings for serialization
105 if (is_iterable($this->body)) {
106 $this->body = $this->bodyToString();
107 }
108
109 $this->_headers = $this->getHeaders();
110
111 return ['_headers', 'body', 'type', 'subtype', 'parameters'];
112 }
113
114 public function __wakeup(): void
115 {
116 $r = new \ReflectionProperty(AbstractPart::class, 'headers');
117 $r->setAccessible(true);
118 $r->setValue($this, $this->_headers);
119 unset($this->_headers);
120 }
121 }
122