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\Multipart;
13
 
14
use Symfony\Component\Mime\Part\AbstractMultipartPart;
15
use Symfony\Component\Mime\Part\AbstractPart;
16
 
17
/**
18
 * @author Fabien Potencier <fabien@symfony.com>
19
 */
20
final class RelatedPart extends AbstractMultipartPart
21
{
22
    private $mainPart;
23
 
24
    public function __construct(AbstractPart $mainPart, AbstractPart $part, AbstractPart ...$parts)
25
    {
26
        $this->mainPart = $mainPart;
27
        $this->prepareParts($part, ...$parts);
28
 
29
        parent::__construct($part, ...$parts);
30
    }
31
 
32
    public function getParts(): array
33
    {
34
        return array_merge([$this->mainPart], parent::getParts());
35
    }
36
 
37
    public function getMediaSubtype(): string
38
    {
39
        return 'related';
40
    }
41
 
42
    private function generateContentId(): string
43
    {
44
        return bin2hex(random_bytes(16)).'@symfony';
45
    }
46
 
47
    private function prepareParts(AbstractPart ...$parts): void
48
    {
49
        foreach ($parts as $part) {
50
            if (!$part->getHeaders()->has('Content-ID')) {
51
                $part->getHeaders()->setHeaderBody('Id', 'Content-ID', $this->generateContentId());
52
            }
53
        }
54
    }
55
}