Completed
Pull Request — master (#116)
by Shingo
02:44 queued 01:18
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
namespace Sichikawa\LaravelSendgridDriver;
3
4
use GuzzleHttp\Client as HttpClient;
5
use Illuminate\Mail\MailManager;
6
use Illuminate\Support\Arr;
7
use Illuminate\Support\ServiceProvider;
8
use Sichikawa\LaravelSendgridDriver\Transport\SendgridTransport;
9
10
class SendgridTransportServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Register the Swift Transport instance.
14
     *
15
     * @return void
16
     */
17
    public function register()
18
    {
19
        $this->app->afterResolving(MailManager::class, function ($mail_manager) {
20
            /** @var $mail_manager MailManager */
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