1
|
|
|
<?php
|
2
|
|
|
/**
|
3
|
|
|
* This file is part of the O2System Framework package.
|
4
|
|
|
*
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE
|
6
|
|
|
* file that was distributed with this source code.
|
7
|
|
|
*
|
8
|
|
|
* @author Steeve Andrian Salim
|
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim
|
10
|
|
|
*/
|
11
|
|
|
|
12
|
|
|
// ------------------------------------------------------------------------
|
13
|
|
|
|
14
|
|
|
namespace O2System\Email;
|
15
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------
|
17
|
|
|
|
18
|
|
|
use O2System\Email\DataStructures\Config;
|
19
|
|
|
use O2System\Email\Protocols\Abstracts\AbstractProtocol;
|
20
|
|
|
use O2System\Spl\Traits\Collectors\ErrorCollectorTrait;
|
21
|
|
|
|
22
|
|
|
/**
|
23
|
|
|
* Class Spool
|
24
|
|
|
*
|
25
|
|
|
* @package O2System\Email
|
26
|
|
|
*/
|
27
|
|
|
class Spool
|
28
|
|
|
{
|
29
|
|
|
use ErrorCollectorTrait;
|
30
|
|
|
|
31
|
|
|
/**
|
32
|
|
|
* Spool::$config
|
33
|
|
|
*
|
34
|
|
|
* Spool configuration.
|
35
|
|
|
*
|
36
|
|
|
* @var Config
|
37
|
|
|
*/
|
38
|
|
|
protected $config;
|
39
|
|
|
|
40
|
|
|
/**
|
41
|
|
|
* Spool::$log
|
42
|
|
|
*
|
43
|
|
|
* Spool log.
|
44
|
|
|
*
|
45
|
|
|
* @var array
|
46
|
|
|
*/
|
47
|
|
|
protected $log = [];
|
48
|
|
|
|
49
|
|
|
// ------------------------------------------------------------------------
|
50
|
|
|
|
51
|
|
|
/**
|
52
|
|
|
* Spool::__construct
|
53
|
|
|
*
|
54
|
|
|
* @param Config|null $config
|
55
|
|
|
*/
|
56
|
|
|
public function __construct(Config $config = null)
|
57
|
|
|
{
|
58
|
|
|
if (empty($config)) {
|
59
|
|
|
$config = new Config();
|
60
|
|
|
}
|
61
|
|
|
|
62
|
|
|
$this->setConfig($config);
|
63
|
|
|
}
|
64
|
|
|
|
65
|
|
|
// ------------------------------------------------------------------------
|
66
|
|
|
|
67
|
|
|
/**
|
68
|
|
|
* Spool::getConfig
|
69
|
|
|
*
|
70
|
|
|
* Gets spool configurations.
|
71
|
|
|
*
|
72
|
|
|
* @return Config
|
73
|
|
|
*/
|
74
|
|
|
public function getConfig()
|
75
|
|
|
{
|
76
|
|
|
return $this->config;
|
77
|
|
|
}
|
78
|
|
|
|
79
|
|
|
// ------------------------------------------------------------------------
|
80
|
|
|
|
81
|
|
|
/**
|
82
|
|
|
* Spool::setConfig
|
83
|
|
|
*
|
84
|
|
|
* Sets spool config.
|
85
|
|
|
*
|
86
|
|
|
* @param Config $config
|
87
|
|
|
*
|
88
|
|
|
* @return static
|
89
|
|
|
*/
|
90
|
|
|
public function setConfig(Config $config)
|
91
|
|
|
{
|
92
|
|
|
$this->config = $config;
|
93
|
|
|
|
94
|
|
|
return $this;
|
95
|
|
|
}
|
96
|
|
|
|
97
|
|
|
// ------------------------------------------------------------------------
|
98
|
|
|
|
99
|
|
|
/**
|
100
|
|
|
* Spool::addLog
|
101
|
|
|
*
|
102
|
|
|
* Add spool log.
|
103
|
|
|
*
|
104
|
|
|
* @param $log
|
105
|
|
|
*/
|
106
|
|
|
public function addLog($log)
|
107
|
|
|
{
|
108
|
|
|
$this->log[] = $log;
|
109
|
|
|
}
|
110
|
|
|
|
111
|
|
|
// ------------------------------------------------------------------------
|
112
|
|
|
|
113
|
|
|
/**
|
114
|
|
|
* Spool::getLog
|
115
|
|
|
*
|
116
|
|
|
* Gets spool log.
|
117
|
|
|
*
|
118
|
|
|
* @return array
|
119
|
|
|
*/
|
120
|
|
|
public function getLog()
|
121
|
|
|
{
|
122
|
|
|
return $this->log;
|
123
|
|
|
}
|
124
|
|
|
|
125
|
|
|
// ------------------------------------------------------------------------
|
126
|
|
|
|
127
|
|
|
/**
|
128
|
|
|
* Spool::send
|
129
|
|
|
*
|
130
|
|
|
* @param \O2System\Email\Message $message
|
131
|
|
|
*
|
132
|
|
|
* @return bool
|
133
|
|
|
*/
|
134
|
|
|
public function send(Message $message)
|
135
|
|
|
{
|
136
|
|
|
$protocolClass = '\O2System\Email\Protocols\\' . ucfirst($this->config->offsetGet('protocol')) . 'Protocol';
|
137
|
|
|
|
138
|
|
|
if (class_exists($protocolClass)) {
|
139
|
|
|
$protocol = new $protocolClass($this);
|
140
|
|
|
|
141
|
|
|
if ($protocol instanceof AbstractProtocol) {
|
142
|
|
|
return $protocol->send($message);
|
143
|
|
|
}
|
144
|
|
|
}
|
145
|
|
|
|
146
|
|
|
return false;
|
147
|
|
|
}
|
148
|
|
|
} |