PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 2.8.16
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v2.8.16
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / vendor / symfony / mime / Part / AbstractMultipartPart.php

AbstractMultipartPart.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 2.8.16, at vendor/symfony/mime/Part/AbstractMultipartPart.php

100 lines 2.4 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 <[email protected]>
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 Fabien Potencier <[email protected]>
18 */
19 abstract class AbstractMultipartPart extends AbstractPart
20 {
21 private $boundary;
22 private $parts = [];
23
24 public function __construct(AbstractPart ...$parts)
25 {
26 parent::__construct();
27
28 foreach ($parts as $part) {
29 $this->parts[] = $part;
30 }
31 }
32
33 /**
34 * @return AbstractPart[]
35 */
36 public function getParts(): array
37 {
38 return $this->parts;
39 }
40
41 public function getMediaType(): string
42 {
43 return 'multipart';
44 }
45
46 public function getPreparedHeaders(): Headers
47 {
48 $headers = parent::getPreparedHeaders();
49 $headers->setHeaderParameter('Content-Type', 'boundary', $this->getBoundary());
50
51 return $headers;
52 }
53
54 public function bodyToString(): string
55 {
56 $parts = $this->getParts();
57 $string = '';
58 foreach ($parts as $part) {
59 $string .= '--'.$this->getBoundary()."\r\n".$part->toString()."\r\n";
60 }
61 $string .= '--'.$this->getBoundary()."--\r\n";
62
63 return $string;
64 }
65
66 public function bodyToIterable(): iterable
67 {
68 $parts = $this->getParts();
69 foreach ($parts as $part) {
70 yield '--'.$this->getBoundary()."\r\n";
71 yield from $part->toIterable();
72 yield "\r\n";
73 }
74 yield '--'.$this->getBoundary()."--\r\n";
75 }
76
77 public function asDebugString(): string
78 {
79 $str = parent::asDebugString();
80 foreach ($this->getParts() as $part) {
81 $lines = explode("\n", $part->asDebugString());
82 $str .= "\n └ ".array_shift($lines);
83 foreach ($lines as $line) {
84 $str .= "\n |".$line;
85 }
86 }
87
88 return $str;
89 }
90
91 private function getBoundary(): string
92 {
93 if (null === $this->boundary) {
94 $this->boundary = strtr(base64_encode(random_bytes(6)), '+/', '-_');
95 }
96
97 return $this->boundary;
98 }
99 }
100