|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use kalanis\EmailApi\Basics; |
|
4
|
|
|
use kalanis\EmailApi\Interfaces; |
|
5
|
|
|
use kalanis\EmailApi\Exceptions; |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
class DummyService implements Interfaces\ISending |
|
9
|
|
|
{ |
|
10
|
|
|
protected bool $canUseService = true; |
|
11
|
|
|
protected bool $getPassedResult = true; |
|
12
|
|
|
protected bool $getFailedResult = true; |
|
13
|
|
|
|
|
14
|
|
|
public function __construct(bool $canUseService = true, bool $getPassedResult = true, bool $getFailedResult = true) |
|
15
|
|
|
{ |
|
16
|
|
|
$this->canUseService = $canUseService; |
|
17
|
|
|
$this->getPassedResult = $getPassedResult; |
|
18
|
|
|
$this->getFailedResult = $getFailedResult; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function canUseService(): bool |
|
22
|
|
|
{ |
|
23
|
|
|
return boolval($this->canUseService); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function systemServiceId(): int |
|
27
|
|
|
{ |
|
28
|
|
|
return static::SERVICE_TESTING; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function sendEmail(Interfaces\IContent $content, Interfaces\IEmailUser $to, ?Interfaces\IEmailUser $from = null, ?Interfaces\IEmailUser $replyTo = null, $toDisabled = false): Basics\Result |
|
32
|
|
|
{ |
|
33
|
|
|
if ($this->getPassedResult) { |
|
34
|
|
|
return new Basics\Result( |
|
35
|
|
|
!empty($content->getHtmlBody()) |
|
36
|
|
|
&& !empty($to->getEmail()), |
|
37
|
|
|
'Dummy service with check' |
|
38
|
|
|
); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
if ($this->getFailedResult) { |
|
42
|
|
|
return new Basics\Result(false, 'died'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
throw new Exceptions\EmailException('die on send'); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|