1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Module\Authentication\Register\Service; |
4
|
|
|
|
5
|
|
|
use App\Infrastructure\Locale\LocaleConfigurator; |
6
|
|
|
use App\Infrastructure\Settings\Settings; |
7
|
|
|
use App\Module\Mail\Service\Mailer; |
|
|
|
|
8
|
|
|
use Symfony\Component\Mailer\Exception\TransportExceptionInterface; |
9
|
|
|
use Symfony\Component\Mime\Address; |
10
|
|
|
use Symfony\Component\Mime\Email; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* This class manages the emails sent in relation to registration. |
14
|
|
|
* |
15
|
|
|
* This is a centralized Service class containing email content and sending action. |
16
|
|
|
* Advantages (compared to having the email content and sending action in the service class that calls this class): |
17
|
|
|
* - Prevents other service classes from having the email responsibility (Single-responsibility principle) |
18
|
|
|
* - Contents are centralized and can be changed easier without having to search them all over the code |
19
|
|
|
*/ |
20
|
|
|
class RegistrationMailSender |
21
|
|
|
{ |
22
|
|
|
private Email $email; |
23
|
|
|
|
24
|
9 |
|
public function __construct( |
25
|
|
|
private readonly Mailer $mailer, |
26
|
|
|
private readonly LocaleConfigurator $localeConfigurator, |
27
|
|
|
Settings $settings, |
28
|
|
|
) { |
29
|
9 |
|
$settings = $settings->get('public')['email']; |
30
|
|
|
// Create email object |
31
|
9 |
|
$this->email = new Email(); |
32
|
|
|
// Send auth emails from domain |
33
|
9 |
|
$this->email->from(new Address($settings['main_sender_address'], $settings['main_sender_name']))->replyTo( |
34
|
9 |
|
$settings['main_contact_email'] |
35
|
9 |
|
)->priority(Email::PRIORITY_HIGH); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Send verification token. |
40
|
|
|
* |
41
|
|
|
* @param string $email |
42
|
|
|
* @param string $fullName |
43
|
|
|
* @param string $language |
44
|
|
|
* @param array $queryParams |
45
|
|
|
* |
46
|
|
|
* @throws TransportExceptionInterface |
47
|
|
|
*/ |
48
|
2 |
|
public function sendRegisterVerificationToken(string $email, string $fullName, string $language, array $queryParams): void |
49
|
|
|
{ |
50
|
|
|
// Change language to one the user is being registered with |
51
|
2 |
|
$originalLocale = setlocale(LC_ALL, 0); |
52
|
2 |
|
$this->localeConfigurator->setLanguage($language); |
53
|
|
|
|
54
|
|
|
// Send verification mail in the language that was selected for the user |
55
|
2 |
|
$this->email->subject(__('Account created')) |
56
|
2 |
|
->html( |
57
|
2 |
|
$this->mailer->getContentFromTemplate( |
58
|
2 |
|
'authentication/email/' . $this->localeConfigurator->getLanguageCodeForPath() . |
59
|
2 |
|
'new-account.email.php', |
60
|
2 |
|
['userFullName' => $fullName, 'queryParams' => $queryParams] |
61
|
2 |
|
) |
62
|
2 |
|
)->to(new Address($email, $fullName)); |
63
|
|
|
// Send email |
64
|
2 |
|
$this->mailer->send($this->email); |
65
|
|
|
|
66
|
|
|
// Reset locale |
67
|
2 |
|
$this->localeConfigurator->setLanguage($originalLocale); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths