|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** Message.php */ |
|
11
|
|
|
namespace Core\Mail; |
|
12
|
|
|
|
|
13
|
|
|
use Auth\Entity\UserInterface; |
|
14
|
|
|
use Traversable; |
|
15
|
|
|
use Zend\Mail\Address; |
|
16
|
|
|
use Zend\Mail\AddressList; |
|
17
|
|
|
use Zend\Mail\Exception; |
|
18
|
|
|
use Zend\Mail\Message as ZfMessage; |
|
19
|
|
|
|
|
20
|
|
|
class Message extends ZfMessage |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
public function __construct(array $options = array()) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->setOptions($options); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function setOptions($options) |
|
29
|
|
|
{ |
|
30
|
|
View Code Duplication |
if (!is_array($options) && !$options instanceof \Traversable) { |
|
|
|
|
|
|
31
|
|
|
throw new \InvalidArgumentException( |
|
32
|
|
|
sprintf( |
|
33
|
|
|
'Expected $options to be an array or \Traversable, but received %s', |
|
34
|
|
|
(is_object($options) ? 'instance of ' . get_class($options) : 'skalar') |
|
35
|
|
|
) |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
View Code Duplication |
foreach ($options as $key => $value) { |
|
|
|
|
|
|
40
|
|
|
$method = "set$key"; |
|
41
|
|
|
if (method_exists($this, $method)) { |
|
42
|
|
|
$this->$method($value); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
return $this; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
protected function updateAddressList(AddressList $addressList, $emailOrAddressOrList, $name, $callingMethod) |
|
49
|
|
|
{ |
|
50
|
|
|
if (null === $emailOrAddressOrList) { |
|
51
|
|
|
return; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
if ($emailOrAddressOrList instanceOf UserInterface) { |
|
55
|
|
|
parent::updateAddressList( |
|
56
|
|
|
$addressList, |
|
57
|
|
|
$emailOrAddressOrList->getInfo()->getEmail(), |
|
58
|
|
|
$emailOrAddressOrList->getInfo()->getDisplayName(false), |
|
59
|
|
|
$callingMethod |
|
60
|
|
|
); |
|
61
|
|
|
return; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
if (is_array($emailOrAddressOrList)) { |
|
65
|
|
|
$list = new AddressList(); |
|
66
|
|
|
foreach ($emailOrAddressOrList as $email => $displayName) { |
|
67
|
|
|
if ($displayName instanceOf UserInterface) { |
|
68
|
|
|
$info = $displayName->getInfo(); |
|
69
|
|
|
$list->add($info->getEmail(), $info->getDisplayName(false)); |
|
70
|
|
|
continue; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
if (is_int($email)) { |
|
74
|
|
|
$email = $displayName; |
|
75
|
|
|
$displayName = null; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$list->add($email, $displayName); |
|
79
|
|
|
} |
|
80
|
|
|
$emailOrAddressOrList = $list; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
parent::updateAddressList($addressList, $emailOrAddressOrList, $name, $callingMethod); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.