|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace izumi\spoolmailer\spools; |
|
4
|
|
|
|
|
5
|
|
|
use Yii; |
|
6
|
|
|
use yii\helpers\FileHelper; |
|
7
|
|
|
use yii\mail\BaseMailer; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Stores Messages on the filesystem. |
|
11
|
|
|
* |
|
12
|
|
|
* @author Viktor Khokhryakov <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
class FileSpool extends BaseSpool |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var string the spool directory |
|
18
|
|
|
*/ |
|
19
|
|
|
public $path = '@runtime/mail_spool'; |
|
20
|
|
|
/** |
|
21
|
|
|
* @var int the permission to be set for newly created spool directory. |
|
22
|
|
|
*/ |
|
23
|
|
|
public $dirMode = 0777; |
|
24
|
|
|
/** |
|
25
|
|
|
* @var int the maximum number of messages to send per flush |
|
26
|
|
|
*/ |
|
27
|
|
|
public $messageLimit = 0; |
|
28
|
|
|
/** |
|
29
|
|
|
* @var int the time limit (in seconds) per flush. |
|
30
|
|
|
*/ |
|
31
|
|
|
public $timeLimit = 30; |
|
32
|
|
|
/** |
|
33
|
|
|
* @var int in second Defaults is for very slow smtp responses |
|
34
|
|
|
*/ |
|
35
|
|
|
public $recoverTimeout = 900; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @inheritdoc |
|
39
|
|
|
*/ |
|
40
|
|
|
public function init() |
|
41
|
|
|
{ |
|
42
|
|
|
parent::init(); |
|
43
|
|
|
$this->path = Yii::getAlias($this->path); |
|
|
|
|
|
|
44
|
|
|
if (!is_dir($this->path)) { |
|
45
|
|
|
FileHelper::createDirectory($this->path, $this->dirMode, true); |
|
46
|
|
|
} |
|
47
|
|
|
$this->setTransport([ |
|
48
|
|
|
'class' => 'Swift_SpoolTransport', |
|
49
|
|
|
'constructArgs' => [ |
|
50
|
|
|
[ |
|
51
|
|
|
'class' => 'Swift_FileSpool', |
|
52
|
|
|
'constructArgs' => [$this->path], |
|
53
|
|
|
], |
|
54
|
|
|
], |
|
55
|
|
|
]); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @inheritdoc |
|
60
|
|
|
*/ |
|
61
|
|
|
public function flush(BaseMailer $mailer, &$failedRecipients = null) |
|
62
|
|
|
{ |
|
63
|
|
|
/** @var \Swift_FileSpool $spool */ |
|
64
|
|
|
$spool = $this->getTransport()->getSpool(); |
|
65
|
|
|
$spool->setTimeLimit($this->timeLimit); |
|
66
|
|
|
$spool->setMessageLimit($this->messageLimit); |
|
67
|
|
|
|
|
68
|
|
|
$spool->recover($this->recoverTimeout); |
|
69
|
|
|
|
|
70
|
|
|
return parent::flush($mailer, $failedRecipients); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.