-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathEclipseServiceProvider.php
More file actions
182 lines (157 loc) · 6.01 KB
/
EclipseServiceProvider.php
File metadata and controls
182 lines (157 loc) · 6.01 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
namespace Eclipse\Core;
use BezhanSalleh\FilamentLanguageSwitch\LanguageSwitch;
use Eclipse\Common\Foundation\Providers\PackageServiceProvider;
use Eclipse\Common\Package;
use Eclipse\Core\Console\Commands\ClearCommand;
use Eclipse\Core\Console\Commands\DeployCommand;
use Eclipse\Core\Console\Commands\PostComposerUpdate;
use Eclipse\Core\Console\Commands\SetupReverb;
use Eclipse\Core\Health\Checks\ReverbCheck;
use Eclipse\Core\Listeners\LogEmailToDatabase;
use Eclipse\Core\Listeners\SendEmailSuccessNotification;
use Eclipse\Core\Models\Locale;
use Eclipse\Core\Models\User;
use Eclipse\Core\Models\User\Permission;
use Eclipse\Core\Models\User\Role;
use Eclipse\Core\Policies\User\RolePolicy;
use Eclipse\Core\Providers\AdminPanelProvider;
use Eclipse\Core\Providers\HorizonServiceProvider;
use Eclipse\Core\Providers\TelescopeServiceProvider;
use Eclipse\Core\Services\Registry;
use Filament\Forms\Components\Field;
use Filament\Infolists\Components\Entry;
use Filament\Resources\Resource;
use Filament\Tables\Columns\Column;
use Illuminate\Auth\Events\Login;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Mail\Events\MessageSent;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Gate;
use Spatie\Health\Checks\Checks\CacheCheck;
use Spatie\Health\Checks\Checks\DebugModeCheck;
use Spatie\Health\Checks\Checks\EnvironmentCheck;
use Spatie\Health\Checks\Checks\HorizonCheck;
use Spatie\Health\Checks\Checks\OptimizedAppCheck;
use Spatie\Health\Checks\Checks\RedisCheck;
use Spatie\Health\Checks\Checks\ScheduleCheck;
use Spatie\Health\Checks\Checks\UsedDiskSpaceCheck;
use Spatie\Health\Facades\Health;
use Spatie\LaravelPackageTools\Package as SpatiePackage;
use Spatie\Permission\PermissionRegistrar;
use Spatie\SecurityAdvisoriesHealthCheck\SecurityAdvisoriesCheck;
class EclipseServiceProvider extends PackageServiceProvider
{
public function configurePackage(SpatiePackage|Package $package): void
{
$package->name('eclipse')
->hasCommands([
ClearCommand::class,
DeployCommand::class,
SetupReverb::class,
PostComposerUpdate::class,
])
->hasConfigFile([
'blade-heroicons',
'eclipse',
'filament-shield',
'horizon',
'log-viewer',
'permission',
'settings',
'telescope',
'themes',
'health',
])
->hasViews()
->hasSettings()
->discoversMigrations()
->runsMigrations()
->hasTranslations()
->hasRoute('console');
}
public function register(): self
{
parent::register();
require_once __DIR__.'/Helpers/helpers.php';
Event::listen(Login::class, function ($event) {
if ($event->user instanceof User) {
$event->user->updateLoginTracking();
}
});
Event::listen(MessageSent::class, SendEmailSuccessNotification::class);
Event::listen(MessageSent::class, LogEmailToDatabase::class);
$this->app->register(AdminPanelProvider::class);
if ($this->app->environment('local')) {
$this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
$this->app->register(TelescopeServiceProvider::class);
}
$this->app->register(HorizonServiceProvider::class);
$this->app->singleton(Registry::class, function () {
return new Registry;
});
return $this;
}
public function boot(): void
{
parent::boot();
// For unit tests...
if (app()->runningUnitTests()) {
// Set the correct user model in auth config
Config::set('auth.providers.users.model', User::class);
}
// Enable Model strictness when not in production
Model::shouldBeStrict(! app()->isProduction());
// Do not allow destructive DB commands in production
DB::prohibitDestructiveCommands(app()->isProduction());
// Set tenancy to off for all resources by default
Resource::scopeToTenant(false);
// Set up Spatie Laravel permissions
app(PermissionRegistrar::class)
->setPermissionClass(Permission::class)
->setRoleClass(Role::class);
// Register policies for classes that can't be guessed automatically
Gate::policy(Role::class, RolePolicy::class);
// Set common settings for Filament form
Field::configureUsing(function (Field $field) {
$field
->translateLabel();
});
// Set common settings for Filament infolist
Entry::configureUsing(function (Entry $entry) {
$entry
->translateLabel();
});
// Set common settings for Filament table columns
Column::configureUsing(function (Column $column) {
$column
->translateLabel()
->toggleable()
->sortable();
});
// Configure language switcher
LanguageSwitch::configureUsing(function (LanguageSwitch $switch) {
$availableLocales = Locale::getAvailableLocales();
$switch
->locales($availableLocales->pluck('id')->toArray())
->labels($availableLocales->pluck('native_name', 'id')->toArray());
});
// Register health checks
Health::checks([
OptimizedAppCheck::new(),
DebugModeCheck::new(),
EnvironmentCheck::new(),
UsedDiskSpaceCheck::new()
->warnWhenUsedSpaceIsAbovePercentage(70)
->failWhenUsedSpaceIsAbovePercentage(90),
CacheCheck::new(),
HorizonCheck::new(),
ReverbCheck::new(),
RedisCheck::new(),
ScheduleCheck::new(),
SecurityAdvisoriesCheck::new(),
]);
}
}