|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Jitamin. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (C) Jitamin Team |
|
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 Jitamin\Foundation\Mail; |
|
13
|
|
|
|
|
14
|
|
|
use Jitamin\Bus\Job\EmailJob; |
|
15
|
|
|
use Jitamin\Foundation\Base; |
|
16
|
|
|
use Pimple\Container; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Mail Client. |
|
20
|
|
|
*/ |
|
21
|
|
|
class Client extends Base |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Mail transport instances. |
|
25
|
|
|
* |
|
26
|
|
|
* @var \Pimple\Container |
|
27
|
|
|
*/ |
|
28
|
|
|
private $transports; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Constructor. |
|
32
|
|
|
* |
|
33
|
|
|
* @param \Pimple\Container $container |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct(Container $container) |
|
36
|
|
|
{ |
|
37
|
|
|
parent::__construct($container); |
|
38
|
|
|
$this->transports = new Container(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Send a HTML email. |
|
43
|
|
|
* |
|
44
|
|
|
* @param string $email |
|
45
|
|
|
* @param string $name |
|
46
|
|
|
* @param string $subject |
|
47
|
|
|
* @param string $html |
|
48
|
|
|
* |
|
49
|
|
|
* @return Client |
|
50
|
|
|
*/ |
|
51
|
|
|
public function send($email, $name, $subject, $html) |
|
52
|
|
|
{ |
|
53
|
|
|
if (!empty($email)) { |
|
54
|
|
|
$this->queueManager->push(EmailJob::getInstance($this->container) |
|
|
|
|
|
|
55
|
|
|
->withParams($email, $name, $subject, $html, $this->getAuthor()) |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Get email author. |
|
64
|
|
|
* |
|
65
|
|
|
* @return string |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getAuthor() |
|
68
|
|
|
{ |
|
69
|
|
|
$author = 'Jitamin'; |
|
70
|
|
|
|
|
71
|
|
|
if ($this->userSession->isLogged()) { |
|
|
|
|
|
|
72
|
|
|
$author = l('%s via Jitamin', $this->helper->user->getFullname()); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return $author; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Get mail transport instance. |
|
80
|
|
|
* |
|
81
|
|
|
* @param string $transport |
|
82
|
|
|
* |
|
83
|
|
|
* @return ClientInterface |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getTransport($transport) |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->transports[$transport]; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Add a new mail transport. |
|
92
|
|
|
* |
|
93
|
|
|
* @param string $transport |
|
94
|
|
|
* @param string $class |
|
95
|
|
|
* |
|
96
|
|
|
* @return Client |
|
97
|
|
|
*/ |
|
98
|
|
|
public function setTransport($transport, $class) |
|
99
|
|
|
{ |
|
100
|
|
|
$container = $this->container; |
|
101
|
|
|
|
|
102
|
|
|
$this->transports[$transport] = function () use ($class, $container) { |
|
103
|
|
|
return new $class($container); |
|
104
|
|
|
}; |
|
105
|
|
|
|
|
106
|
|
|
return $this; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Return the list of registered transports. |
|
111
|
|
|
* |
|
112
|
|
|
* @return array |
|
113
|
|
|
*/ |
|
114
|
|
|
public function getAvailableTransports() |
|
115
|
|
|
{ |
|
116
|
|
|
$availableTransports = $this->transports->keys(); |
|
117
|
|
|
|
|
118
|
|
|
return array_combine($availableTransports, $availableTransports); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.