Tweak service providers for code readability

This commit is contained in:
Pig Fang 2018-07-23 08:56:24 +08:00
parent 3cf5c646c6
commit 93b3a165ab
2 changed files with 29 additions and 15 deletions

View File

@ -22,20 +22,8 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot()
{
// 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()) {
$this->app['url']->forceScheme('https');
}
View::addExtension('tpl', 'blade');
// Control the URL generated by url() function
$this->configureUrlGenerator();
Event::listen(Events\RenderingHeader::class, function($event) {
// Provide some application information for javascript
@ -72,5 +60,32 @@ class AppServiceProvider extends ServiceProvider
if ($this->app->environment() !== 'production') {
$this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}
// Support *.tpl extension name
View::addExtension('tpl', 'blade');
}
/**
* Configure the \Illuminate\Routing\UrlGenerator.
*
* @return void
*
* @codeCoverageIgnore
*/
protected function configureUrlGenerator()
{
if (! option('auto_detect_asset_url')) {
$rootUrl = option('site_url');
// Replace HTTP_HOST with site_url set in options,
// to prevent CDN source problems.
if ($this->app['url']->isValidUrl($rootUrl)) {
$this->app['url']->forceRootUrl($rootUrl);
}
}
if (option('force_ssl') || Utils::isRequestSecure()) {
$this->app['url']->forceSchema('https');
}
}
}

View File

@ -231,7 +231,6 @@ return [
'Option' => App\Services\Facades\Option::class,
'Utils' => App\Services\Utils::class,
'Minecraft' => App\Services\Minecraft::class,
'Updater' => App\Services\Updater::class,
],
];