misc_pterodactyl-panel/app/Providers/AppServiceProvider.php

80 lines
2.2 KiB
PHP
Raw Normal View History

<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
2017-09-26 02:43:01 +00:00
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Providers;
use View;
use Cache;
use Pterodactyl\Models;
use Pterodactyl\Observers;
2017-09-25 03:34:30 +00:00
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*/
public function boot()
{
2017-09-25 03:34:30 +00:00
Schema::defaultStringLength(191);
Models\User::observe(Observers\UserObserver::class);
Models\Server::observe(Observers\ServerObserver::class);
Models\Subuser::observe(Observers\SubuserObserver::class);
View::share('appVersion', $this->versionData()['version'] ?? 'undefined');
View::share('appIsGit', $this->versionData()['is_git'] ?? false);
}
/**
* Register any application services.
*/
public function register()
{
2017-03-15 23:47:44 +00:00
if ($this->app->environment() !== 'production') {
$this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}
if (config('pterodactyl.auth.notifications')) {
$this->app->register(\DaneEveritt\LoginNotifications\NotificationServiceProvider::class);
}
}
/**
* Return version information for the footer.
*
* @return array
*/
protected function versionData()
{
return Cache::remember('git-version', 5, function () {
if (file_exists(base_path('.git/HEAD'))) {
$head = explode(' ', file_get_contents(base_path('.git/HEAD')));
2017-07-23 22:55:38 +00:00
if (array_key_exists(1, $head)) {
$path = base_path('.git/' . trim($head[1]));
}
}
if (isset($path) && file_exists($path)) {
return [
'version' => substr(file_get_contents($path), 0, 8),
'is_git' => true,
];
}
return [
'version' => config('app.version'),
'is_git' => false,
];
});
}
}