Test Failed
Push — master ( 62e8aa...e74fb5 )
by Julien
04:23
created

ServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 5
Bugs 2 Features 0
Metric Value
eloc 15
c 5
b 2
f 0
dl 0
loc 24
ccs 0
cts 14
cp 0
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 20 2
1
<?php
2
3
/**
4
 * This file is part of the Zemit Framework.
5
 *
6
 * (c) Zemit Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zemit\Provider\Mailer;
13
14
use Phalcon\Di\DiInterface;
15
use Phalcon\Events\ManagerInterface;
16
use Phalcon\Mailer\Manager;
17
use Zemit\Config\ConfigInterface;
18
use Zemit\Provider\AbstractServiceProvider;
19
20
class ServiceProvider extends AbstractServiceProvider
21
{
22
    protected string $serviceName = 'mailer';
23
    
24
    public function register(DiInterface $di): void
25
    {
26
        $di->setShared($this->getName(), function () use ($di) {
27
    
28
            $config = $di->get('config');
29
            assert($config instanceof ConfigInterface);
30
    
31
            $mailerConfig = $config->pathToArray('mailer', []);
32
            
33
            $driver = $mailerConfig['driver'] ?? '';
34
            $defaultOptions = $mailerConfig['defaults'] ?? [];
35
            $driverOptions = $mailerConfig['drivers'][$driver] ?? [];
36
            $options = array_merge($defaultOptions, $driverOptions);
37
    
38
            $manager = new Manager($options);
39
            $manager->setDI($di);
40
            
41
            $eventsManager = $di->get('eventsManager');
42
            if ($eventsManager instanceof ManagerInterface) {
43
                $manager->setEventsManager($eventsManager);
44
            }
45
        });
46
    }
47
}
48