Files
speedtest-tracker/app/Providers/AppServiceProvider.php
T

85 lines
2.1 KiB
PHP

<?php
namespace App\Providers;
use App\Services\SystemChecker;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Console\AboutCommand;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* The path to your application's "home" route.
*
* Typically, users are redirected here after authentication.
*
* @var string
*/
public const HOME = '/';
/**
* Register any application services.
*/
public function register(): void
{
if ($this->app->environment('local')) {
$this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
$this->app->register(TelescopeServiceProvider::class);
}
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
$this->defineCustomIfStatements();
$this->setApiRateLimit();
if (config('app.force_https')) {
URL::forceScheme('https');
}
$system = new SystemChecker;
AboutCommand::add('Speedtest Tracker', fn () => [
'Version' => $system->getLocalVersion(),
'Out of date' => $system->isOutOfDate() ? 'Yes' : 'No',
]);
}
/**
* Define custom if statements, these were added to make the blade templates more readable.
*
* Ref: https://github.com/laravel/framework/pull/51561
*/
protected function defineCustomIfStatements(): void
{
/**
* Adds blank() custom if statement.
*/
Blade::if('blank', function (mixed $value) {
return blank($value);
});
/**
* Adds filled() custom if statement.
*/
Blade::if('filled', function (mixed $value) {
return filled($value);
});
}
protected function setApiRateLimit(): void
{
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(config('api.rate_limit'));
});
}
}