Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Providers/AppServiceProvider.php
7432 views
1
<?php
2
3
namespace Pterodactyl\Providers;
4
5
use Pterodactyl\Models;
6
use Illuminate\Support\Str;
7
use Illuminate\Support\Facades\URL;
8
use Illuminate\Pagination\Paginator;
9
use Illuminate\Support\Facades\View;
10
use Illuminate\Support\Facades\Cache;
11
use Illuminate\Support\Facades\Schema;
12
use Illuminate\Support\ServiceProvider;
13
use Pterodactyl\Extensions\Themes\Theme;
14
use Illuminate\Database\Eloquent\Relations\Relation;
15
16
class AppServiceProvider extends ServiceProvider
17
{
18
/**
19
* Bootstrap any application services.
20
*/
21
public function boot(): void
22
{
23
Schema::defaultStringLength(191);
24
25
View::share('appVersion', $this->versionData()['version'] ?? 'undefined');
26
View::share('appIsGit', $this->versionData()['is_git'] ?? false);
27
28
Paginator::useBootstrap();
29
30
// If the APP_URL value is set with https:// make sure we force it here. Theoretically
31
// this should just work with the proxy logic, but there are a lot of cases where it
32
// doesn't, and it triggers a lot of support requests, so lets just head it off here.
33
//
34
// @see https://github.com/pterodactyl/panel/issues/3623
35
if (Str::startsWith(config('app.url') ?? '', 'https://')) {
36
URL::forceScheme('https');
37
}
38
39
Relation::enforceMorphMap([
40
'allocation' => Models\Allocation::class,
41
'api_key' => Models\ApiKey::class,
42
'backup' => Models\Backup::class,
43
'database' => Models\Database::class,
44
'egg' => Models\Egg::class,
45
'egg_variable' => Models\EggVariable::class,
46
'schedule' => Models\Schedule::class,
47
'server' => Models\Server::class,
48
'ssh_key' => Models\UserSSHKey::class,
49
'task' => Models\Task::class,
50
'user' => Models\User::class,
51
]);
52
}
53
54
/**
55
* Register application service providers.
56
*/
57
public function register(): void
58
{
59
// Only load the settings service provider if the environment
60
// is configured to allow it.
61
if (!config('pterodactyl.load_environment_only', false) && $this->app->environment() !== 'testing') {
62
$this->app->register(SettingsServiceProvider::class);
63
}
64
65
$this->app->singleton('extensions.themes', function () {
66
return new Theme();
67
});
68
}
69
70
/**
71
* Return version information for the footer.
72
*/
73
protected function versionData(): array
74
{
75
return Cache::remember('git-version', 5, function () {
76
if (file_exists(base_path('.git/HEAD'))) {
77
$head = explode(' ', file_get_contents(base_path('.git/HEAD')));
78
79
if (array_key_exists(1, $head)) {
80
$path = base_path('.git/' . trim($head[1]));
81
}
82
}
83
84
if (isset($path) && file_exists($path)) {
85
return [
86
'version' => substr(file_get_contents($path), 0, 8),
87
'is_git' => true,
88
];
89
}
90
91
return [
92
'version' => config('app.version'),
93
'is_git' => false,
94
];
95
});
96
}
97
}
98
99