1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* Copyright (c) Phauthentic (https://github.com/Phauthentic) |
5
|
|
|
* |
6
|
|
|
* Licensed under The MIT License |
7
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
8
|
|
|
* Redistributions of files must retain the above copyright notice. |
9
|
|
|
* |
10
|
|
|
* @copyright Copyright (c) Phauthentic (https://github.com/Phauthentic) |
11
|
|
|
* @link https://github.com/Phauthentic |
12
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License |
13
|
|
|
*/ |
14
|
|
|
namespace Phauthentic\Email\Mailer; |
15
|
|
|
|
16
|
|
|
use Cake\Mailer\Email as CakeEmail; |
17
|
|
|
use Phauthentic\Email\EmailInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Abstract Cake mailer |
21
|
|
|
*/ |
22
|
|
|
class CakePhpMailer implements MailerInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Cake Email Instance |
26
|
|
|
* |
27
|
|
|
* @var \Cake\Mailer\Email |
28
|
|
|
*/ |
29
|
|
|
protected $cakeEmail; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Constructor |
33
|
|
|
* |
34
|
|
|
* @param \Cake\Mailer\Email $cakeEmail Cake Email |
35
|
|
|
*/ |
36
|
|
|
public function __construct(CakeEmail $cakeEmail) |
37
|
|
|
{ |
38
|
|
|
$this->cakeEmail = $cakeEmail; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* |
43
|
|
|
*/ |
44
|
|
|
public function setCakeEmail(CakeEmail $cakeEmail): MailerInterface |
45
|
|
|
{ |
46
|
|
|
$this->cakeEmail = $cakeEmail; |
47
|
|
|
|
48
|
|
|
return $this; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @inheritDoc |
53
|
|
|
*/ |
54
|
|
|
public function send(EmailInterface $email): bool |
55
|
|
|
{ |
56
|
|
|
$cakeEmail = clone $this->cakeEmail; |
57
|
|
|
|
58
|
|
|
$cakeEmail->setSubject($email->getSubject()); |
59
|
|
|
$cakeEmail->setSender($email->getEmail(), $email->getName()); |
|
|
|
|
60
|
|
|
|
61
|
|
|
foreach ($email->getReceivers() as $recevier) { |
62
|
|
|
$cakeEmail->addTo($recevier->getEmail(), $recevier->getName()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$html = $email->getHtmlContent(); |
66
|
|
|
$text = $email->getTextContent(); |
67
|
|
|
|
68
|
|
|
if (!empty($html) && !empty($text)) { |
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$cakeEmail->send(); |
73
|
|
|
|
74
|
|
|
return true; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.