96 lines
2.7 KiB
PHP
96 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Application\Data\PageMeta;
|
|
use App\Models\SiteSetting;
|
|
use Carbon\CarbonImmutable;
|
|
use Illuminate\Cache\RateLimiting\Limit;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\RateLimiter;
|
|
use Illuminate\Support\Facades\View;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Illuminate\View\View as ViewInstance;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register any application services.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
$this->configureLivewireTemporaryUploads();
|
|
$this->freezeClockWhenConfigured();
|
|
$this->configureRateLimiters();
|
|
|
|
View::composer('layouts.public', function (ViewInstance $view): void {
|
|
$settings = $view->offsetExists('siteSettings')
|
|
? $view->offsetGet('siteSettings')
|
|
: SiteSetting::instance();
|
|
|
|
if (! $view->offsetExists('siteSettings')) {
|
|
$view->with('siteSettings', $settings);
|
|
}
|
|
|
|
if (! $view->offsetExists('pageMeta')) {
|
|
$view->with('pageMeta', PageMeta::forPage(
|
|
canonical: url()->current(),
|
|
settings: $settings,
|
|
));
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Keep Livewire/Filament temp uploads on the local disk.
|
|
*
|
|
* When FILESYSTEM_DISK=r2, Livewire would otherwise use the S3 driver and
|
|
* browser-PUT straight to R2 (CORS). Final media still uses the r2 disk via
|
|
* PublicImageUploadRules. Explicit LIVEWIRE_TEMPORARY_FILE_UPLOAD_DISK wins.
|
|
*/
|
|
private function configureLivewireTemporaryUploads(): void
|
|
{
|
|
if (filled(config('livewire.temporary_file_upload.disk'))) {
|
|
return;
|
|
}
|
|
|
|
config(['livewire.temporary_file_upload.disk' => 'local']);
|
|
}
|
|
|
|
private function configureRateLimiters(): void
|
|
{
|
|
RateLimiter::for('contact-briefing', function (Request $request): Limit {
|
|
return Limit::perMinute(5)->by($request->ip().'|contact-briefing');
|
|
});
|
|
|
|
RateLimiter::for('partner-inquiry', function (Request $request): Limit {
|
|
return Limit::perMinute(5)->by($request->ip().'|partner-inquiry');
|
|
});
|
|
}
|
|
|
|
private function freezeClockWhenConfigured(): void
|
|
{
|
|
if ($this->app->environment('production')) {
|
|
return;
|
|
}
|
|
|
|
$frozenNow = config('app.frozen_now');
|
|
|
|
if (! filled($frozenNow)) {
|
|
return;
|
|
}
|
|
|
|
CarbonImmutable::setTestNow(CarbonImmutable::parse((string) $frozenNow));
|
|
}
|
|
}
|