-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathLaravelMailatorServiceProvider.php
105 lines (88 loc) · 4.05 KB
/
LaravelMailatorServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace Binarcode\LaravelMailator;
use Binarcode\LaravelMailator\Console\Commands\GarbageCollectorCommand;
use Binarcode\LaravelMailator\Console\Commands\MailatorSchedulerCommand;
use Binarcode\LaravelMailator\Console\Commands\PruneMailatorLogsCommand;
use Binarcode\LaravelMailator\Console\Commands\PruneMailatorScheduleCommand;
use Binarcode\LaravelMailator\Models\MailatorLog;
use Binarcode\LaravelMailator\Models\MailatorSchedule;
use Binarcode\LaravelMailator\Models\MailTemplate;
use Binarcode\LaravelMailator\Models\MailTemplatePlaceholder;
use Illuminate\Support\ServiceProvider;
class LaravelMailatorServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*/
public function boot()
{
if (config('mailator.scheduler.model')) {
$this->app->bind(MailatorSchedule::class, config('mailator.model'));
}
if (config('mailator.log_model')) {
$this->app->bind(MailatorLog::class, config('mailator.log_model'));
}
if (config('mailator.templates.template_model')) {
$this->app->bind(MailTemplate::class, config('mailator.templates.template_model'));
}
if (config('mailator.templates.placeholder_model')) {
$this->app->bind(MailTemplatePlaceholder::class, config('mailator.templates.placeholder_model'));
}
/*
* Optional methods to load your package assets
*/
// $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'laravel-mailator');
$this->loadViewsFrom(__DIR__.'/../resources/views/publish', 'laravel-mailator');
// $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
// $this->loadRoutesFrom(__DIR__.'/routes.php');
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/../config/mailator.php' => config_path('mailator.php'),
], 'mailator-config');
if (! class_exists('CreateMailatorTables')) {
$this->publishes([
__DIR__ . '/../database/migrations/create_mailator_tables.php.stub' => database_path('migrations/' . date('Y_m_d_His', now()->subMinute()->timestamp) . '_create_mailator_tables.php'),
], 'mailator-migrations');
}
if (! class_exists('AlterMailLogsTableAddCascadeDelete')) {
$this->publishes([
__DIR__ . '/../database/migrations/alter_mail_logs_table_add_cascade_delete.php.stub' => database_path('migrations/' . date('Y_m_d_His', now()->timestamp) . '_alter_mail_logs_table_add_cascade_delete.php'),
], 'mailator-migrations');
}
// Publishing the views.
$this->publishes([
__DIR__.'/../resources/views/publish' => resource_path('views/vendor/laravel-mailator'),
], 'mailator-views');
// Publishing assets.
/*$this->publishes([
__DIR__.'/../resources/assets' => public_path('vendor/laravel-mailator'),
], 'assets');*/
// Publishing the translation files.
/*$this->publishes([
__DIR__.'/../resources/lang' => resource_path('lang/vendor/laravel-mailator'),
], 'lang');*/
// Registering package commands.
$this->commands([
GarbageCollectorCommand::class,
MailatorSchedulerCommand::class,
PruneMailatorScheduleCommand::class,
PruneMailatorLogsCommand::class,
]);
}
}
/**
* Register the application services.
*/
public function register()
{
// Automatically apply the package configuration
$this->mergeConfigFrom(__DIR__.'/../config/mailator.php', 'mailator');
// Register the main class to use with the facade
$this->app->singleton('mailator', function () {
return new MailatorManager();
});
$this->app->singleton('mailator-scheduler', function () {
return new SchedulerManager();
});
}
}