1 | <?php |
||
2 | /** |
||
3 | * This file is part of the ZBateson\MailMimeParser project. |
||
4 | * |
||
5 | * @license http://opensource.org/licenses/bsd-license.php BSD |
||
6 | */ |
||
7 | |||
8 | namespace ZBateson\MailMimeParser\Header; |
||
9 | |||
10 | use Psr\Log\LoggerInterface; |
||
11 | use ZBateson\MailMimeParser\Header\Consumer\IdBaseConsumerService; |
||
12 | use ZBateson\MailMimeParser\Header\Part\CommentPart; |
||
13 | use ZBateson\MailMimeParser\Header\Part\MimeTokenPartFactory; |
||
14 | use ZBateson\MailMimeParser\MailMimeParser; |
||
15 | |||
16 | /** |
||
17 | * Represents a Content-ID, Message-ID, In-Reply-To or References header. |
||
18 | * |
||
19 | * For a multi-id header like In-Reply-To or References, all IDs can be |
||
20 | * retrieved by calling {@see IdHeader::getIds()}. Otherwise, to retrieve the |
||
21 | * first (or only) ID call {@see IdHeader::getValue()}. |
||
22 | * |
||
23 | * @author Zaahid Bateson |
||
24 | */ |
||
25 | class IdHeader extends MimeEncodedHeader |
||
26 | { |
||
27 | 91 | public function __construct( |
|
28 | string $name, |
||
29 | string $value, |
||
30 | ?LoggerInterface $logger = null, |
||
31 | ?MimeTokenPartFactory $mimeTokenPartFactory = null, |
||
32 | ?IdBaseConsumerService $consumerService = null |
||
33 | ) { |
||
34 | 91 | $di = MailMimeParser::getGlobalContainer(); |
|
35 | 91 | parent::__construct( |
|
36 | 91 | $logger ?? $di->get(LoggerInterface::class), |
|
37 | 91 | $mimeTokenPartFactory ?? $di->get(MimeTokenPartFactory::class), |
|
38 | 91 | $consumerService ?? $di->get(IdBaseConsumerService::class), |
|
39 | 91 | $name, |
|
40 | 91 | $value |
|
41 | 91 | ); |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * Returns the ID. Synonymous to calling getValue(). |
||
46 | * |
||
47 | * @return string|null The ID |
||
48 | */ |
||
49 | public function getId() : ?string |
||
50 | { |
||
51 | return $this->getValue(); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Returns all IDs parsed for a multi-id header like References or |
||
56 | * In-Reply-To. |
||
57 | * |
||
58 | * @return string[] An array of IDs |
||
59 | */ |
||
60 | 6 | public function getIds() : array |
|
61 | { |
||
62 | 6 | return \array_values(\array_map( |
|
63 | 6 | function($p) { |
|
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
64 | 5 | return $p->getValue(); |
|
65 | 6 | }, |
|
66 | 6 | \array_filter($this->parts, function($p) { |
|
0 ignored issues
–
show
|
|||
67 | 5 | return !($p instanceof CommentPart); |
|
68 | 6 | }) |
|
69 | 6 | )); |
|
70 | } |
||
71 | } |
||
72 |