2024-05-13 18:55:34 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
2024-08-29 15:46:10 -04:00
|
|
|
use App\Models\Mod;
|
2024-07-26 02:19:42 -04:00
|
|
|
use App\Models\ModDependency;
|
|
|
|
use App\Models\ModVersion;
|
2024-08-22 17:04:07 -04:00
|
|
|
use App\Models\SptVersion;
|
2024-06-19 13:20:51 -04:00
|
|
|
use App\Models\User;
|
2024-07-26 02:19:42 -04:00
|
|
|
use App\Observers\ModDependencyObserver;
|
2024-08-29 15:46:10 -04:00
|
|
|
use App\Observers\ModObserver;
|
2024-07-26 02:19:42 -04:00
|
|
|
use App\Observers\ModVersionObserver;
|
2024-08-22 17:04:07 -04:00
|
|
|
use App\Observers\SptVersionObserver;
|
2024-09-13 00:08:00 -04:00
|
|
|
use Carbon\Carbon;
|
2024-07-04 22:10:48 -04:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2024-06-19 13:20:51 -04:00
|
|
|
use Illuminate\Support\Facades\Gate;
|
2024-08-09 00:35:18 -04:00
|
|
|
use Illuminate\Support\Number;
|
2024-05-13 18:55:34 -04:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Register any application services.
|
|
|
|
*/
|
|
|
|
public function register(): void
|
|
|
|
{
|
2024-09-09 23:07:57 -04:00
|
|
|
//
|
2024-05-13 18:55:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bootstrap any application services.
|
|
|
|
*/
|
|
|
|
public function boot(): void
|
|
|
|
{
|
2024-07-04 22:10:48 -04:00
|
|
|
// Allow mass assignment for all models. Be careful!
|
|
|
|
Model::unguard();
|
|
|
|
|
2024-09-09 23:07:57 -04:00
|
|
|
$this->registerObservers();
|
|
|
|
|
|
|
|
$this->registerNumberMacros();
|
|
|
|
$this->registerCarbonMacros();
|
2024-07-26 02:19:42 -04:00
|
|
|
|
2024-06-19 13:20:51 -04:00
|
|
|
// This gate determines who can access the Pulse dashboard.
|
|
|
|
Gate::define('viewPulse', function (User $user) {
|
|
|
|
return $user->isAdmin();
|
|
|
|
});
|
2024-09-09 23:07:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register model observers.
|
|
|
|
*/
|
|
|
|
private function registerObservers(): void
|
|
|
|
{
|
|
|
|
Mod::observe(ModObserver::class);
|
|
|
|
ModVersion::observe(ModVersionObserver::class);
|
|
|
|
ModDependency::observe(ModDependencyObserver::class);
|
|
|
|
SptVersion::observe(SptVersionObserver::class);
|
|
|
|
}
|
2024-08-09 00:35:18 -04:00
|
|
|
|
2024-09-09 23:07:57 -04:00
|
|
|
/**
|
|
|
|
* Register custom number macros.
|
|
|
|
*/
|
|
|
|
private function registerNumberMacros(): void
|
|
|
|
{
|
|
|
|
// Format download numbers.
|
2024-08-09 00:35:18 -04:00
|
|
|
Number::macro('downloads', function (int|float $number) {
|
|
|
|
return Number::forHumans(
|
|
|
|
$number,
|
|
|
|
$number > 1000000 ? 2 : ($number > 1000 ? 1 : 0),
|
|
|
|
maxPrecision: null,
|
|
|
|
abbreviate: true
|
|
|
|
);
|
|
|
|
});
|
2024-05-13 18:55:34 -04:00
|
|
|
}
|
2024-09-09 23:07:57 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Register custom Carbon macros.
|
|
|
|
*/
|
|
|
|
private function registerCarbonMacros(): void
|
|
|
|
{
|
|
|
|
// Format dates dynamically based on the time passed.
|
|
|
|
Carbon::macro('dynamicFormat', function (Carbon $date) {
|
|
|
|
if ($date->diff(now())->m > 1) {
|
|
|
|
return $date->format('M jS, Y');
|
|
|
|
}
|
|
|
|
if ($date->diff(now())->d === 0) {
|
|
|
|
return $date->diffForHumans();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $date->format('M jS, g:i A');
|
|
|
|
});
|
|
|
|
}
|
2024-05-13 18:55:34 -04:00
|
|
|
}
|