Files
fewo-stommer/app/Providers/AppServiceProvider.php

60 lines
2.3 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Providers;
use App\Process\ProcessCatalogue;
use App\Process\Tester\SandboxBootstrapper;
use App\Support\StripImageMetadata;
use App\Support\SystemSettings;
use App\Tenancy\TenantConfig;
use App\Tenancy\TenantContext;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;
use Spatie\MediaLibrary\MediaCollections\Events\MediaHasBeenAddedEvent;
use Throwable;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
$this->app->singleton(TenantContext::class);
$this->app->singleton(TenantConfig::class);
$this->app->singleton(ProcessCatalogue::class);
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
// Settings of the installation first (they become the baseline a landlord may tighten), then the
// operating data of the landlord: addresses, periods and test mode, which sends every e-mail to the
// test recipient only until a landlord is switched live. Console and boot know the landlord only if
// there is exactly one.
try {
// A process tester run keeps its own, closed configuration (SandboxBootstrapper): no stored operator
// settings – they carry SMTP and other access data – are laid over it.
if (! SandboxBootstrapper::active()) {
SystemSettings::apply();
}
$this->app->make(TenantConfig::class)->refresh();
} catch (Throwable) {
// no database yet (package discovery, first install)
}
// Photos: remove metadata (GPS position, camera data) from uploaded originals, which stay downloadable.
Event::listen(MediaHasBeenAddedEvent::class, fn (MediaHasBeenAddedEvent $event) => StripImageMetadata::strip($event->media));
// On Strato the domain points at the deployment folder and .htaccess forwards to current/public;
// without a fixed root, some URLs (e.g. /sitemap.xml) would be generated with /current/public.
if (! $this->app->environment('local', 'testing')) {
URL::forceRootUrl(config('app.url'));
URL::forceScheme(parse_url((string) config('app.url'), PHP_URL_SCHEME) ?: 'https');
}
}
}