1
|
|
|
<?php |
2
|
|
|
namespace FMUP; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Class Mail - PHPMailer decorator |
6
|
|
|
* @package FMUP |
7
|
|
|
* @todo implement a real mail manager system |
8
|
|
|
*/ |
9
|
|
|
class Mail extends \PHPMailer |
10
|
|
|
{ |
11
|
|
|
private $config; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @param Config\ConfigInterface $config |
15
|
|
|
* @param bool|false $exceptions |
16
|
|
|
*/ |
17
|
2 |
|
public function __construct(\FMUP\Config\ConfigInterface $config, $exceptions = false) |
18
|
|
|
{ |
19
|
2 |
|
parent::__construct($exceptions); |
20
|
2 |
|
$this->config = $config; |
21
|
|
|
|
22
|
2 |
|
if ($config->get('smtp_serveur') != 'localhost') { |
23
|
2 |
|
$this->IsSMTP(); |
24
|
|
|
} |
25
|
2 |
|
$this->IsHTML(true); |
26
|
2 |
|
$this->CharSet = "UTF-8"; |
27
|
2 |
|
$this->SMTPAuth = $config->get('smtp_authentification'); |
|
|
|
|
28
|
2 |
|
$this->SMTPSecure = $config->get('smtp_secure'); |
|
|
|
|
29
|
2 |
|
$this->SMTPAutoTLS = $config->get('smtp_secure') == 'tls'; |
30
|
|
|
|
31
|
2 |
|
$this->Host = $config->get('smtp_serveur'); |
|
|
|
|
32
|
2 |
|
$this->Port = $config->get('smtp_port'); |
|
|
|
|
33
|
|
|
|
34
|
2 |
|
if ($config->get('smtp_authentification')) { |
35
|
1 |
|
$this->Username = $config->get('smtp_username'); // Gmail identifiant |
|
|
|
|
36
|
1 |
|
$this->Password = $config->get('smtp_password'); // Gmail mot de passe |
|
|
|
|
37
|
|
|
} |
38
|
2 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Remplace tokens in a string |
42
|
|
|
* @param string $message Text to parse |
43
|
|
|
* @param array $tokens Associative array for tokens to replace |
44
|
|
|
* @return string treated message |
45
|
|
|
* @uses self::tokenReplaceMap |
46
|
|
|
*/ |
47
|
1 |
|
public static function replaceTokens($message = '', array $tokens = array()) |
48
|
|
|
{ |
49
|
1 |
|
$search = array_keys($tokens); |
50
|
1 |
|
$replace = array_values($tokens); |
51
|
1 |
|
$search = array_map(array(__CLASS__, 'tokenReplaceMap'), $search); |
52
|
1 |
|
return str_replace($search, $replace, $message); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Replace map |
57
|
|
|
* @param string $o |
58
|
|
|
* @return string |
59
|
|
|
* @usedby self::replaceTokens |
60
|
|
|
* @SuppressWarnings(PMD.UnusedPrivateMethod) |
61
|
|
|
*/ |
62
|
1 |
|
private static function tokenReplaceMap($o) |
63
|
|
|
{ |
64
|
1 |
|
return "{" . $o . "}"; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
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
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. 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.