Path: blob/1.0-develop/app/Providers/AppServiceProvider.php
7432 views
<?php12namespace Pterodactyl\Providers;34use Pterodactyl\Models;5use Illuminate\Support\Str;6use Illuminate\Support\Facades\URL;7use Illuminate\Pagination\Paginator;8use Illuminate\Support\Facades\View;9use Illuminate\Support\Facades\Cache;10use Illuminate\Support\Facades\Schema;11use Illuminate\Support\ServiceProvider;12use Pterodactyl\Extensions\Themes\Theme;13use Illuminate\Database\Eloquent\Relations\Relation;1415class AppServiceProvider extends ServiceProvider16{17/**18* Bootstrap any application services.19*/20public function boot(): void21{22Schema::defaultStringLength(191);2324View::share('appVersion', $this->versionData()['version'] ?? 'undefined');25View::share('appIsGit', $this->versionData()['is_git'] ?? false);2627Paginator::useBootstrap();2829// If the APP_URL value is set with https:// make sure we force it here. Theoretically30// this should just work with the proxy logic, but there are a lot of cases where it31// doesn't, and it triggers a lot of support requests, so lets just head it off here.32//33// @see https://github.com/pterodactyl/panel/issues/362334if (Str::startsWith(config('app.url') ?? '', 'https://')) {35URL::forceScheme('https');36}3738Relation::enforceMorphMap([39'allocation' => Models\Allocation::class,40'api_key' => Models\ApiKey::class,41'backup' => Models\Backup::class,42'database' => Models\Database::class,43'egg' => Models\Egg::class,44'egg_variable' => Models\EggVariable::class,45'schedule' => Models\Schedule::class,46'server' => Models\Server::class,47'ssh_key' => Models\UserSSHKey::class,48'task' => Models\Task::class,49'user' => Models\User::class,50]);51}5253/**54* Register application service providers.55*/56public function register(): void57{58// Only load the settings service provider if the environment59// is configured to allow it.60if (!config('pterodactyl.load_environment_only', false) && $this->app->environment() !== 'testing') {61$this->app->register(SettingsServiceProvider::class);62}6364$this->app->singleton('extensions.themes', function () {65return new Theme();66});67}6869/**70* Return version information for the footer.71*/72protected function versionData(): array73{74return Cache::remember('git-version', 5, function () {75if (file_exists(base_path('.git/HEAD'))) {76$head = explode(' ', file_get_contents(base_path('.git/HEAD')));7778if (array_key_exists(1, $head)) {79$path = base_path('.git/' . trim($head[1]));80}81}8283if (isset($path) && file_exists($path)) {84return [85'version' => substr(file_get_contents($path), 0, 8),86'is_git' => true,87];88}8990return [91'version' => config('app.version'),92'is_git' => false,93];94});95}96}979899