|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Distilleries\MailerSaver; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Mail\MailServiceProvider; |
|
6
|
|
|
use Distilleries\MailerSaver\Helpers\Mail; |
|
7
|
|
|
use Distilleries\MailerSaver\Contracts\MailModelContract; |
|
8
|
|
|
|
|
9
|
|
|
class MailerSaverServiceProvider extends MailServiceProvider |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Indicates if loading of the provider is deferred. |
|
13
|
|
|
* |
|
14
|
|
|
* @var bool |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $defer = false; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Bootstrap any application services. |
|
20
|
|
|
* |
|
21
|
|
|
* @return void |
|
22
|
|
|
*/ |
|
23
|
16 |
|
public function boot() |
|
24
|
|
|
{ |
|
25
|
16 |
|
$this->loadViewsFrom(__DIR__ . '/../../views', 'mailersaver'); |
|
26
|
|
|
|
|
27
|
16 |
|
$this->publishes([ |
|
28
|
16 |
|
__DIR__ . '/../../config/config.php' => config_path('mailersaver.php'), |
|
29
|
|
|
]); |
|
30
|
|
|
|
|
31
|
16 |
|
$this->publishes([ |
|
32
|
16 |
|
__DIR__ . '/../../views' => base_path('resources/views/vendor/mailersaver'), |
|
33
|
16 |
|
], 'views'); |
|
34
|
|
|
|
|
35
|
16 |
|
$this->publishes([ |
|
36
|
16 |
|
__DIR__ . '/../../models/Email.php' => base_path('app/Email.php'), |
|
37
|
16 |
|
], 'models'); |
|
38
|
|
|
|
|
39
|
16 |
|
$this->publishes([ |
|
40
|
16 |
|
__DIR__ . '/../../database/migrations/' => base_path('/database/migrations') |
|
41
|
16 |
|
], 'migrations'); |
|
42
|
|
|
|
|
43
|
16 |
|
$this->mergeConfigFrom( |
|
44
|
16 |
|
__DIR__ . '/../../config/config.php', 'mailersaver' |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
16 |
|
protected function registerIlluminateMailer() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->app->singleton('mailer', function ($app) { |
|
51
|
12 |
|
$config = $app->make('config')->get('mail'); |
|
52
|
|
|
|
|
53
|
|
|
// Once we have create the mailer instance, we will set a container instance |
|
54
|
|
|
// on the mailer. This allows us to resolve mailer classes via containers |
|
55
|
|
|
// for maximum testability on said classes instead of passing Closures. |
|
56
|
12 |
|
$mailer = new Mail( |
|
57
|
12 |
|
$app->make(MailModelContract::class), $app['view'], $app['swift.mailer'], $app['events'] |
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
12 |
|
if ($app->bound('queue')) { |
|
61
|
12 |
|
$mailer->setQueue($app['queue']); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
// Next we will set all of the global addresses on this mailer, which allows |
|
65
|
|
|
// for easy unification of all "from" addresses as well as easy debugging |
|
66
|
|
|
// of sent messages since they get be sent into a single email address. |
|
67
|
12 |
|
foreach (['from', 'reply_to', 'to'] as $type) { |
|
68
|
12 |
|
$this->setGlobalAddress($mailer, $config, $type); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
12 |
|
return $mailer; |
|
72
|
16 |
|
}); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|