Completed
Push — master ( 9c95f5...e428dc )
by Paweł
06:06
created

Mailer::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
cc 2
eloc 18
nc 2
nop 6
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 2016 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 2016 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\UserBundle\Mailer;
18
19
use FOS\UserBundle\Mailer\Mailer as FOSMailer;
20
use SWP\Bundle\SettingsBundle\Manager\SettingsManagerInterface;
21
use SWP\Bundle\SettingsBundle\Model\SettingsOwnerInterface;
22
use SWP\Component\MultiTenancy\Context\TenantContextInterface;
23
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
24
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
25
26
class Mailer extends FOSMailer
27
{
28
    /**
29
     * Mailer constructor.
30
     *
31
     * @param \Swift_Mailer            $mailer
32
     * @param UrlGeneratorInterface    $router
33
     * @param EngineInterface          $templating
34
     * @param array                    $parameters
35
     * @param SettingsManagerInterface $settingsManager
36
     */
37
    public function __construct(
38
        $mailer,
39
        UrlGeneratorInterface $router,
40
        EngineInterface $templating,
41
        array $parameters,
42
        SettingsManagerInterface $settingsManager,
43
        TenantContextInterface $tenantContext
44
    ) {
45
        $this->mailer = $mailer;
46
        $this->router = $router;
47
        $this->templating = $templating;
48
        $this->parameters = $parameters;
49
        $tenant = $tenantContext->getTenant();
50
51
        if ($tenant instanceof SettingsOwnerInterface) {
52
            $fromEmail = ['contact@'.$tenant->getDomainName() => 'contact'];
53
54
            $this->parameters['confirmation.template'] = $settingsManager->get('registration_confirmation.template', 'tenant', $tenant);
55
            $this->parameters['from_email']['confirmation'] = $settingsManager->get('registration_from_email.confirmation', 'tenant', $tenant, $fromEmail);
56
            $this->parameters['resetting.template'] = $settingsManager->get('registration_resetting.template', 'tenant', $tenant);
57
            $this->parameters['from_email']['resetting'] = $settingsManager->get('registration_from_email.resetting', 'tenant', $tenant, $fromEmail);
58
        }
59
    }
60
}
61