blessing-skin-server/app/Providers/AppServiceProvider.php

72 lines
2.1 KiB
PHP
Raw Normal View History

2016-08-28 10:05:21 +08:00
<?php
namespace App\Providers;
use Blade;
use Event;
use Utils;
use App\Events;
use App\Models\User;
use ReflectionException;
2016-08-28 10:05:21 +08:00
use Illuminate\Support\ServiceProvider;
use App\Exceptions\PrettyPageException;
2016-08-28 10:05:21 +08:00
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
2018-02-16 17:31:04 +08:00
// Replace HTTP_HOST with site url setted in options to prevent CDN source problems
if (! option('auto_detect_asset_url')) {
$rootUrl = option('site_url');
if ($this->app['url']->isValidUrl($rootUrl)) {
$this->app['url']->forceRootUrl($rootUrl);
}
}
if (option('force_ssl') || Utils::isRequestSecure()) {
2018-07-13 21:23:07 +08:00
$this->app['url']->forceScheme('https');
}
Event::listen(Events\RenderingHeader::class, function($event) {
2018-02-16 17:31:04 +08:00
// Provide some application information for javascript
2017-01-18 22:57:15 +08:00
$blessing = array_merge(array_except(config('app'), ['key', 'providers', 'aliases', 'cipher', 'log', 'url']), [
'base_url' => url('/'),
'site_name' => option_localized('site_name')
]);
$event->addContent('<script>var blessing = '.json_encode($blessing).';</script>');
});
try {
$this->app->make('cipher');
} catch (ReflectionException $e) {
throw new PrettyPageException(trans('errors.cipher.unsupported', ['cipher' => config('secure.cipher')]));
}
2016-08-28 10:05:21 +08:00
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->singleton('cipher', 'App\Services\Cipher\\'.config('secure.cipher'));
2016-10-23 11:41:52 +08:00
$this->app->singleton('users', \App\Services\Repositories\UserRepository::class);
Blade::if('admin', function (User $user) {
return $user->isAdmin();
});
2018-07-18 10:36:12 +08:00
if ($this->app->environment() !== 'production') {
$this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}
2016-08-28 10:05:21 +08:00
}
}