MailTemplateServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 10
c 2
b 0
f 1
1
<?php
2
3
namespace DansMaCulotte\MailTemplate;
4
5
use DansMaCulotte\MailTemplate\Drivers\MailgunDriver;
6
use DansMaCulotte\MailTemplate\Drivers\MailjetDriver;
7
use DansMaCulotte\MailTemplate\Drivers\MandrillDriver;
8
use DansMaCulotte\MailTemplate\Drivers\NullDriver;
9
use DansMaCulotte\MailTemplate\Drivers\SendgridDriver;
10
use DansMaCulotte\MailTemplate\Drivers\SendinblueDriver;
11
use DansMaCulotte\MailTemplate\Exceptions\InvalidConfiguration;
12
use Illuminate\Support\ServiceProvider;
13
14
class MailTemplateServiceProvider extends ServiceProvider
15
{
16
    /**
17
     * Bootstrap the application services.
18
     */
19
    public function boot()
20
    {
21
        $this->mergeConfigFrom(__DIR__.'/../config/mail-template.php', 'mail-template');
22
23
        $this->publishes([
24
            __DIR__.'/../config/mail-template.php' => config_path('mail-template.php'),
25
        ]);
26
    }
27
28
    /**
29
     * Register the application services.
30
     */
31
    public function register()
32
    {
33
        $this->app->singleton(MailTemplate::class, function () {
34
            $driver = config('mail-template.driver', null);
35
            if (is_null($driver) || $driver === 'log') {
36
                return new NullDriver($driver === 'log');
37
            }
38
39
            switch ($driver) {
40
                case 'mailjet':
41
                    $driver = new MailjetDriver(config('mail-template.mailjet'));
42
                    break;
43
                case 'mandrill':
44
                    $driver = new MandrillDriver(config('mail-template.mandrill'));
45
                    break;
46
                case 'sendgrid':
47
                    $driver = new SendgridDriver(config('mail-template.sendgrid'));
48
                    break;
49
                case 'mailgun':
50
                    $driver = new MailgunDriver(config('mail-template.mailgun'));
51
                    break;
52
                case 'sendinblue':
53
                    $driver = new SendinblueDriver(config('mail-template.sendinblue'));
54
                    break;
55
                default:
56
                    throw InvalidConfiguration::driverNotFound($driver);
57
                    break;
58
            }
59
60
            return new MailTemplate($driver);
61
        });
62
63
        $this->app->alias(MailTemplate::class, 'mail-template');
64
    }
65
}
66