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\Header;
13
 
14
use Symfony\Component\Mime\Address;
15
use Symfony\Component\Mime\Exception\RfcComplianceException;
16
 
17
/**
18
 * An ID MIME Header for something like Message-ID or Content-ID (one or more addresses).
19
 *
20
 * @author Chris Corbyn
21
 */
22
final class IdentificationHeader extends AbstractHeader
23
{
24
    private array $ids = [];
25
    private array $idsAsAddresses = [];
26
 
27
    public function __construct(string $name, string|array $ids)
28
    {
29
        parent::__construct($name);
30
 
31
        $this->setId($ids);
32
    }
33
 
34
    /**
35
     * @param string|string[] $body a string ID or an array of IDs
36
     *
37
     * @throws RfcComplianceException
38
     */
39
    public function setBody(mixed $body)
40
    {
41
        $this->setId($body);
42
    }
43
 
44
    public function getBody(): array
45
    {
46
        return $this->getIds();
47
    }
48
 
49
    /**
50
     * Set the ID used in the value of this header.
51
     *
52
     * @param string|string[] $id
53
     *
54
     * @throws RfcComplianceException
55
     */
56
    public function setId(string|array $id)
57
    {
58
        $this->setIds(\is_array($id) ? $id : [$id]);
59
    }
60
 
61
    /**
62
     * Get the ID used in the value of this Header.
63
     *
64
     * If multiple IDs are set only the first is returned.
65
     */
66
    public function getId(): ?string
67
    {
68
        return $this->ids[0] ?? null;
69
    }
70
 
71
    /**
72
     * Set a collection of IDs to use in the value of this Header.
73
     *
74
     * @param string[] $ids
75
     *
76
     * @throws RfcComplianceException
77
     */
78
    public function setIds(array $ids)
79
    {
80
        $this->ids = [];
81
        $this->idsAsAddresses = [];
82
        foreach ($ids as $id) {
83
            $this->idsAsAddresses[] = new Address($id);
84
            $this->ids[] = $id;
85
        }
86
    }
87
 
88
    /**
89
     * Get the list of IDs used in this Header.
90
     *
91
     * @return string[]
92
     */
93
    public function getIds(): array
94
    {
95
        return $this->ids;
96
    }
97
 
98
    public function getBodyAsString(): string
99
    {
100
        $addrs = [];
101
        foreach ($this->idsAsAddresses as $address) {
102
            $addrs[] = '<'.$address->toString().'>';
103
        }
104
 
105
        return implode(' ', $addrs);
106
    }
107
}