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

63 lines
1.8 KiB
PHP
Raw Normal View History

2016-08-28 10:05:21 +08:00
<?php
namespace App\Providers;
use Event;
use Utils;
use App\Events;
2016-08-28 10:05:21 +08:00
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
2016-09-27 22:15:51 +08:00
// replace HTTP_HOST with site url setted in options to prevent CDN source problems
2016-10-23 11:41:52 +08:00
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()) {
$this->app['url']->forceSchema('https');
}
Event::listen(Events\RenderingHeader::class, function($event) {
// 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('site_name')
]);
$event->addContent('<script>var blessing = '.json_encode($blessing).';</script>');
});
2016-08-28 10:05:21 +08:00
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
2016-10-23 11:41:52 +08:00
// register default cipher
$className = "App\Services\Cipher\\".config('secure.cipher');
if (class_exists($className)) {
$this->app->singleton('cipher', $className);
} else {
exit(sprintf("No such encrypt method: [%s], please check your .env configuration.", config('secure.cipher')));
}
2016-10-23 11:41:52 +08:00
$this->app->singleton('users', \App\Services\Repositories\UserRepository::class);
2016-12-30 20:47:38 +08:00
$this->app->singleton('parsedown', \Parsedown::class);
2016-08-28 10:05:21 +08:00
}
}