1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of slick/mail package |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Slick\Mail\Header; |
11
|
|
|
|
12
|
|
|
use Slick\Common\Utils\Collection\AbstractCollection; |
13
|
|
|
use Slick\Mail\Header\AddressList\AddressInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* E-Mail Address List Header |
17
|
|
|
* |
18
|
|
|
* @package Slick\Mail\Header |
19
|
|
|
* @author Filipe Silva <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class AddressList extends AbstractCollection implements AddressListInterface |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $name; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $value; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Methods implementing HeaderInterface |
36
|
|
|
*/ |
37
|
|
|
use HeaderCommonMethods; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Address List |
41
|
|
|
* |
42
|
|
|
* @param string $name |
43
|
|
|
* |
44
|
|
|
*/ |
45
|
18 |
|
public function __construct($name) |
46
|
|
|
{ |
47
|
18 |
|
$this->name = $name; |
48
|
18 |
|
parent::__construct([]); |
49
|
18 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Adds an address to the address list |
53
|
|
|
* |
54
|
|
|
* @param AddressInterface $address |
55
|
|
|
* |
56
|
|
|
* @return AddressListInterface |
57
|
|
|
*/ |
58
|
16 |
|
public function add(AddressInterface $address) |
59
|
|
|
{ |
60
|
16 |
|
$this->data[] = $address; |
61
|
16 |
|
return $this; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Returns the string version of this header |
67
|
|
|
* |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
16 |
|
public function toString() |
71
|
|
|
{ |
72
|
16 |
|
$parts = []; |
73
|
|
|
/** @var AddressInterface $address */ |
74
|
16 |
|
foreach ($this as $address) { |
75
|
16 |
|
$parts[] = (String) $address; |
76
|
8 |
|
} |
77
|
16 |
|
$addresses = implode(',', $parts); |
78
|
16 |
|
return "{$this->getName()}: {$addresses}"; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Offset to set |
83
|
|
|
* |
84
|
|
|
* @link http://php.net/manual/en/arrayaccess.offsetset.php |
85
|
|
|
* |
86
|
|
|
* @param mixed $offset The offset to assign the value to. |
87
|
|
|
* @param mixed $value The value to set. |
88
|
|
|
* |
89
|
|
|
* @codeCoverageIgnore |
90
|
|
|
*/ |
91
|
|
|
public function offsetSet($offset, $value) |
92
|
|
|
{ |
93
|
|
|
$this->add($value); |
94
|
|
|
} |
95
|
|
|
} |