1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Superdesk Web Publisher User Bundle. |
7
|
|
|
* |
8
|
|
|
* Copyright 2021 Sourcefabric z.ú. and contributors. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please see the |
11
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
12
|
|
|
* |
13
|
|
|
* @Copyright 2021 Sourcefabric z.ú |
14
|
|
|
* @license http://www.superdesk.org/license |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace SWP\Bundle\UserBundle\Mailer; |
18
|
|
|
|
19
|
|
|
use SWP\Bundle\SettingsBundle\Manager\SettingsManagerInterface; |
20
|
|
|
use SWP\Bundle\SettingsBundle\Model\SettingsOwnerInterface; |
21
|
|
|
use SWP\Component\MultiTenancy\Context\TenantContextInterface; |
22
|
|
|
use Symfony\Component\Mailer\MailerInterface as BaseMailerInterface; |
23
|
|
|
|
24
|
|
|
class TenantAwareMailer extends Mailer |
25
|
|
|
{ |
26
|
|
|
public function __construct( |
27
|
|
|
BaseMailerInterface $mailer, |
28
|
|
|
array $parameters, |
29
|
|
|
SettingsManagerInterface $settingsManager, |
30
|
|
|
TenantContextInterface $tenantContext = null |
31
|
|
|
) { |
32
|
|
|
$this->mailer = $mailer; |
33
|
|
|
$this->parameters = $parameters; |
34
|
|
|
$tenant = $tenantContext->getTenant(); |
|
|
|
|
35
|
|
|
|
36
|
|
|
if ($tenant instanceof SettingsOwnerInterface) { |
37
|
|
|
$fromEmail = ['contact@'.$tenant->getDomainName() => 'contact']; |
38
|
|
|
|
39
|
|
|
$this->parameters['confirmation.template'] = |
40
|
|
|
$settingsManager->get('registration_confirmation.template', 'tenant', $tenant); |
41
|
|
|
$this->parameters['from_email']['confirmation'] = |
42
|
|
|
$settingsManager->get('registration_from_email.confirmation', 'tenant', $tenant, $fromEmail); |
43
|
|
|
$this->parameters['resetting.template'] = |
44
|
|
|
$settingsManager->get('registration_resetting.template', 'tenant', $tenant); |
45
|
|
|
$this->parameters['from_email']['resetting'] = |
46
|
|
|
$settingsManager->get('registration_from_email.resetting', 'tenant', $tenant, $fromEmail); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: