|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Qodeboy\Mailman; |
|
4
|
|
|
|
|
5
|
|
|
use Swift_Mailer; |
|
6
|
|
|
use Illuminate\Mail\MailServiceProvider; |
|
7
|
|
|
use Qodeboy\Mailman\Transport\MailmanTransport; |
|
8
|
|
|
use Qodeboy\Mailman\Logger\MailmanDatabaseLogger; |
|
9
|
|
|
use Qodeboy\Mailman\Logger\MailmanFilesystemLogger; |
|
10
|
|
|
|
|
11
|
|
|
class MailmanServiceProvider extends MailServiceProvider |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Perform post-registration booting of services. |
|
15
|
|
|
* |
|
16
|
|
|
* @return void |
|
17
|
|
|
*/ |
|
18
|
|
|
public function boot() |
|
19
|
|
|
{ |
|
20
|
|
|
$this->publishes([ |
|
21
|
|
|
__DIR__.'/../config/mailman.php' => config_path('mailman.php'), |
|
22
|
|
|
]); |
|
23
|
|
|
|
|
24
|
|
|
$this->publishes([ |
|
25
|
|
|
__DIR__.'/../migrations/2016_04_12_000000_create_mailman_messages_table.php' => base_path('database/migrations/2016_04_12_000000_create_mailman_messages_table.php'), |
|
26
|
|
|
]); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Register any package services. |
|
31
|
|
|
* |
|
32
|
|
|
* @return void |
|
33
|
|
|
*/ |
|
34
|
|
|
public function register() |
|
35
|
|
|
{ |
|
36
|
|
|
parent::register(); |
|
37
|
|
|
|
|
38
|
|
|
$this->mergeConfigFrom( |
|
39
|
|
|
__DIR__.'/../config/mailman.php', 'mailman' |
|
40
|
|
|
); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Register the Swift Mailer instance. |
|
45
|
|
|
* |
|
46
|
|
|
* @return void |
|
47
|
|
|
*/ |
|
48
|
|
|
public function registerSwiftMailer() |
|
49
|
|
|
{ |
|
50
|
|
|
if ($this->app['config']['mail.driver'] == 'mailman') { |
|
51
|
|
|
$this->registerMailmanSwiftMailer(); |
|
52
|
|
|
$this->registerMailmanLogger(); |
|
53
|
|
|
} else { |
|
54
|
|
|
parent::registerSwiftMailer(); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Register Mailman Logger. |
|
60
|
|
|
*/ |
|
61
|
|
|
public function registerMailmanLogger() |
|
62
|
|
|
{ |
|
63
|
|
|
$this->app->singleton('mailman.logger', function ($app) { |
|
64
|
|
|
$storageAdapter = $app['config']['mailman']['log']['storage']; |
|
65
|
|
|
|
|
66
|
|
|
if (! in_array($storageAdapter, ['database', 'filesystem'])) { |
|
67
|
|
|
throw new \RuntimeException("Invalid log storage adapter was supplied! Adapter \"{$storageAdapter}\" is not supported!"); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
switch ($storageAdapter) { |
|
71
|
|
|
case 'filesystem': |
|
72
|
|
|
return new MailmanFilesystemLogger(); |
|
73
|
|
|
|
|
74
|
|
|
case 'database': |
|
75
|
|
|
default: |
|
76
|
|
|
return new MailmanDatabaseLogger(); |
|
77
|
|
|
} |
|
78
|
|
|
}); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Register the Mailman Swift Mailer instance. |
|
83
|
|
|
* |
|
84
|
|
|
* @return void |
|
85
|
|
|
*/ |
|
86
|
|
|
protected function registerMailmanSwiftMailer() |
|
87
|
|
|
{ |
|
88
|
|
|
$this->registerSwiftTransport(); |
|
89
|
|
|
|
|
90
|
|
|
$this->app->singleton('swift.mailer', function ($app) { |
|
91
|
|
|
return new Swift_Mailer( |
|
92
|
|
|
new MailmanTransport($app) |
|
93
|
|
|
); |
|
94
|
|
|
}); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|