Completed
Pull Request — master (#116)
by Shingo
02:35 queued 01:33
created

SendgridTransportServiceProvider::extendTransportManager()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 1
nop 1
1
<?php
2
3
namespace Sichikawa\LaravelSendgridDriver;
4
5
use GuzzleHttp\Client as HttpClient;
6
use Illuminate\Mail\MailManager;
7
use Illuminate\Support\Arr;
8
use Illuminate\Support\ServiceProvider;
9
use Sichikawa\LaravelSendgridDriver\Transport\SendgridTransport;
10
11
class SendgridTransportServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Register the Swift Transport instance.
15
     *
16
     * @return void
17
     */
18
    public function register()
19
    {
20
        $this->app->afterResolving(MailManager::class, function (MailManager $mail_manager) {
21
            $mail_manager->extend("sendgrid", function ($config) {
22
                $client = new HttpClient(Arr::get($config, 'guzzle', []));
23
                $endpoint = isset($config['endpoint']) ? $config['endpoint'] : null;
24
25
                return new SendgridTransport($client, $config['api_key'], $endpoint);
26
            });
27
28
        });
29
    }
30
}
31