This commit is contained in:
Pig Fang 2019-12-25 15:59:20 +08:00
parent facd92356c
commit ad1201b226
3 changed files with 24 additions and 18 deletions

View File

@ -0,0 +1,20 @@
<?php
namespace App\Listeners;
class SerializeGlobals
{
public function handle($event)
{
$blessing = [
'version' => config('app.version'),
'locale' => config('app.locale'),
'fallback_locale' => config('app.fallback_locale'),
'base_url' => url('/'),
'site_name' => option_localized('site_name'),
'route' => request()->path(),
'extra' => [],
];
$event->addContent('<script>const blessing = '.json_encode($blessing).';</script>');
}
}

View File

@ -2,10 +2,8 @@
namespace App\Providers;
use App\Events;
use App\Exceptions\PrettyPageException;
use App\Services;
use Event;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\ServiceProvider;
@ -32,27 +30,13 @@ class AppServiceProvider extends ServiceProvider
/**
* Bootstrap any application services.
*
* @return void
* @codeCoverageIgnore
*/
public function boot(Request $request)
{
// Control the URL generated by url() function
$this->configureUrlGenerator($request);
Event::listen(Events\RenderingHeader::class, function ($event) {
$blessing = [
'version' => config('app.version'),
'locale' => config('app.locale'),
'fallback_locale' => config('app.fallback_locale'),
'base_url' => url('/'),
'site_name' => option_localized('site_name'),
'route' => request()->path(),
'extra' => [],
];
$event->addContent('<script>var blessing = '.json_encode($blessing).';</script>');
});
// @codeCoverageIgnoreStart
try {
$this->app->make('cipher');
} catch (\Illuminate\Contracts\Container\BindingResolutionException $e) {
@ -69,7 +53,6 @@ class AppServiceProvider extends ServiceProvider
}
} catch (\Exception $e) {
}
// @codeCoverageIgnoreEnd
}
/**

View File

@ -32,6 +32,9 @@ class EventServiceProvider extends ServiceProvider
'App\Events\PluginBootFailed' => [
'App\Listeners\NotifyFailedPlugin',
],
'App\Events\RenderingHeader' => [
'App\Listeners\SerializeGlobals',
],
];
/**