1 | <?php |
||
13 | class HeloLaravelServiceProvider extends ServiceProvider |
||
14 | { |
||
15 | /** |
||
16 | * Bootstrap the application services. |
||
17 | */ |
||
18 | public function boot() |
||
19 | { |
||
20 | if ($this->app->runningUnitTests() || !$this->app['config']['helo.is_enabled']) { |
||
21 | return; |
||
22 | } |
||
23 | |||
24 | $instance = app()->make(Mailer::class); |
||
25 | |||
26 | Mail::swap($instance); |
||
27 | |||
28 | app()->instance(MailerContract::class, $instance); |
||
29 | |||
30 | if ($this->app->runningInConsole()) { |
||
31 | View::addNamespace('helo', __DIR__ . '/../resources/views'); |
||
32 | } |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Register the application services. |
||
37 | */ |
||
38 | public function register() |
||
39 | { |
||
40 | if ($this->app->runningInConsole()) { |
||
41 | $this->commands([ |
||
42 | TestMailCommand::class, |
||
43 | ]); |
||
44 | |||
45 | $this->publishes([ |
||
46 | __DIR__.'/../config/helo.php' => base_path('config/helo.php'), |
||
47 | ], 'config'); |
||
48 | } |
||
49 | |||
50 | $this->mergeConfigFrom(__DIR__.'/../config/helo.php', 'helo'); |
||
51 | |||
52 | $this->app->singleton(Mailer::class, function ($app) { |
||
53 | if (version_compare($app->version(), '7.0.0', '<')) { |
||
54 | return $this->createLaravel6Mailer($app); |
||
55 | } |
||
56 | |||
57 | return $this->createLaravel7Mailer($app); |
||
58 | }); |
||
59 | } |
||
60 | |||
61 | protected function createLaravel6Mailer($app) |
||
85 | |||
86 | protected function createLaravel7Mailer($app) |
||
114 | |||
115 | protected function getConfig($name = 'smtp') |
||
121 | |||
122 | /** |
||
123 | * Set a global address on the mailer by type. |
||
124 | * |
||
125 | * @param \Illuminate\Mail\Mailer $mailer |
||
126 | * @param array $config |
||
127 | * @param string $type |
||
128 | * @return void |
||
129 | */ |
||
130 | protected function setGlobalAddress($mailer, array $config, $type) |
||
142 | } |
||
143 |