2016-08-28 10:05:21 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
2016-12-10 22:01:05 +08:00
|
|
|
use Event;
|
2017-01-08 13:14:14 +08:00
|
|
|
use Utils;
|
2016-12-10 22:01:05 +08:00
|
|
|
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()
|
|
|
|
{
|
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')) {
|
2016-12-16 22:13:41 +08:00
|
|
|
$rootUrl = option('site_url');
|
|
|
|
|
|
|
|
if ($this->app['url']->isValidUrl($rootUrl)) {
|
|
|
|
$this->app['url']->forceRootUrl($rootUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-08 13:14:14 +08:00
|
|
|
if (option('force_ssl') || Utils::isRequestSecure()) {
|
2016-12-16 22:13:41 +08:00
|
|
|
$this->app['url']->forceSchema('https');
|
2016-10-17 09:46:57 +08:00
|
|
|
}
|
2016-12-10 22:01:05 +08:00
|
|
|
|
|
|
|
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']), [
|
2017-01-14 23:33:01 +08:00
|
|
|
'base_url' => url('/'),
|
|
|
|
'site_name' => option('site_name')
|
2016-12-10 22:01:05 +08:00
|
|
|
]);
|
|
|
|
|
|
|
|
$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()
|
|
|
|
{
|
2018-02-16 17:31:04 +08:00
|
|
|
// Register default cipher
|
2017-01-08 12:49:32 +08:00
|
|
|
$className = "App\Services\Cipher\\".config('secure.cipher');
|
|
|
|
|
|
|
|
if (class_exists($className)) {
|
|
|
|
$this->app->singleton('cipher', $className);
|
|
|
|
} else {
|
2018-02-24 19:21:04 +08:00
|
|
|
die_with_utf8_encoding(sprintf(
|
|
|
|
'[Error] Unsupported encryption method: < %1$s >, please check your .env configuration <br>'.
|
|
|
|
'[错误] 不支持的密码加密方式 < %1$s >,请检查你的 .env 配置文件'
|
|
|
|
, config('secure.cipher')));
|
2017-01-08 12:49:32 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|