1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal; |
4
|
|
|
|
5
|
|
|
use Drupal\Driver\DriverInterface; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Default implementation of the Drupal mail manager service. |
9
|
|
|
* |
10
|
|
|
* This uses Drupal core's test_mail_collector mail backend, which both |
11
|
|
|
* collects outbound mail and prevents it from being sent. Therefore using |
12
|
|
|
* this implementation, mail is collected if and only if sending is disabled. |
13
|
|
|
*/ |
14
|
|
|
class DrupalMailManager implements DrupalMailManagerInterface { |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The active Drupal driver. |
18
|
|
|
* |
19
|
|
|
* @var \Drupal\Driver\DriverInterface |
20
|
|
|
*/ |
21
|
|
|
protected $driver; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The name or config array of the initial mail backend. |
25
|
|
|
* |
26
|
|
|
* @var mixed |
27
|
|
|
*/ |
28
|
|
|
protected $initialMailBackend; |
29
|
|
|
|
30
|
|
|
public function __construct(DriverInterface $driver) { |
31
|
|
|
$this->driver = $driver; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Replace the initial mail backend with the test mail backend. |
36
|
|
|
*/ |
37
|
|
|
protected function enableTestMailBackend() { |
38
|
|
|
if (is_null($this->initialMailBackend)) { |
39
|
|
|
$this->initialMailBackend = $this->driver->getMailBackend(); |
|
|
|
|
40
|
|
|
} |
41
|
|
|
// @todo Use a collector that supports html after D#2223967 lands. |
42
|
|
|
$this->driver->setMailBackend('test_mail_collector'); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Restore the initial mail backend. |
47
|
|
|
*/ |
48
|
|
|
protected function restoreInitialMailBackend() { |
49
|
|
|
$this->driver->setMailBackend($this->initialMailBackend); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
|
|
public function startCollectingMail() { |
56
|
|
|
$this->enableTestMailBackend(); |
57
|
|
|
$this->clearMail(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
|
|
public function stopCollectingMail() { |
64
|
|
|
$this->restoreInitialMailBackend(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
|
|
public function enableMail() { |
71
|
|
|
$this->restoreInitialMailBackend(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
|
|
public function disableMail() { |
78
|
|
|
$this->startCollectingMail(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@inheritdoc} |
83
|
|
|
*/ |
84
|
|
|
public function getMail($store = 'default') { |
85
|
|
|
return $this->driver->getMail(); |
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* {@inheritdoc} |
90
|
|
|
*/ |
91
|
|
|
public function clearMail($store = 'default') { |
92
|
|
|
$this->driver->clearMail(); |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
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.