|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace app\modules\core\components; |
|
4
|
|
|
|
|
5
|
|
|
use app\commands\SubmissionsController; |
|
6
|
|
|
use app\modules\core\components\mail\SendMailHandler; |
|
7
|
|
|
use yii\base\BootstrapInterface; |
|
8
|
|
|
use yii\base\Event; |
|
9
|
|
|
use yii\swiftmailer\Mailer; |
|
10
|
|
|
|
|
11
|
|
|
class MailComponent extends Mailer implements BootstrapInterface |
|
12
|
|
|
{ |
|
13
|
|
|
private $componentConfig = []; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Bootstrap method to be called during application bootstrap stage. |
|
17
|
|
|
* @param Application $app the application currently running |
|
18
|
|
|
*/ |
|
19
|
|
|
public function bootstrap($app) |
|
20
|
|
|
{ |
|
21
|
|
|
if ($app instanceof \yii\console\Application === true) { |
|
|
|
|
|
|
22
|
|
|
Event::on( |
|
23
|
|
|
SubmissionsController::className(), |
|
24
|
|
|
SubmissionsController::EVENT_SEND_SUBMISSIONS, |
|
25
|
|
|
[ |
|
26
|
|
|
SendMailHandler::class, |
|
27
|
|
|
'submissionsSendMail' |
|
28
|
|
|
] |
|
29
|
|
|
); |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @inheritdoc |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct($config = []) |
|
38
|
|
|
{ |
|
39
|
|
|
parent::__construct($config); |
|
40
|
|
|
|
|
41
|
|
|
$this->componentConfig = $mailConfig = \Yii::$app->getModule('core')->emailConfig; |
|
42
|
|
|
|
|
43
|
|
|
$_config = [ |
|
44
|
|
|
'class' => $mailConfig['transport'], |
|
45
|
|
|
]; |
|
46
|
|
|
|
|
47
|
|
|
if ('Swift_SmtpTransport' === $mailConfig['transport']) { |
|
48
|
|
|
$_config['host'] = $mailConfig['host']; |
|
49
|
|
|
$_config['username'] = $mailConfig['username']; |
|
50
|
|
|
$_config['password'] = $mailConfig['password']; |
|
51
|
|
|
$_config['port'] = $mailConfig['port']; |
|
52
|
|
|
$_config['encryption'] = $mailConfig['encryption']; |
|
53
|
|
|
} elseif ('Swift_SendmailTransport' === $mailConfig['transport']) { |
|
54
|
|
|
$_config['command'] = $mailConfig['sendMail']; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$this->setTransport($_config); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return string |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getMailFrom() |
|
64
|
|
|
{ |
|
65
|
|
|
return !empty($this->componentConfig['mailFrom']) |
|
66
|
|
|
? $this->componentConfig['mailFrom'] |
|
67
|
|
|
: ''; |
|
68
|
|
|
} |
|
69
|
|
|
} |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.