2016-08-28 10:05:21 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
2016-09-04 15:47:51 +08:00
|
|
|
use View;
|
2016-12-10 22:01:05 +08:00
|
|
|
use Event;
|
2016-09-03 23:50:55 +08:00
|
|
|
use Validator;
|
2016-12-10 22:01:05 +08:00
|
|
|
use App\Events;
|
|
|
|
use Illuminate\Support\Arr;
|
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
|
|
|
|
preg_match('/https?:\/\/([^\/]+)\/?.*/', option('site_url'), $host);
|
|
|
|
|
2016-10-23 11:41:52 +08:00
|
|
|
if (!option('auto_detect_asset_url')) {
|
2016-10-17 09:46:57 +08:00
|
|
|
// check if host is valid
|
|
|
|
if (isset($host[1]) && '' === preg_replace('/(?:^\[)?[a-zA-Z0-9-:\]_]+\.?/', '', $host[1])) {
|
|
|
|
$this->app['request']->headers->set('host', $host[1]);
|
|
|
|
};
|
|
|
|
}
|
2016-12-10 22:01:05 +08:00
|
|
|
|
|
|
|
Event::listen(Events\RenderingHeader::class, function($event) {
|
|
|
|
// provide some application information for javascript
|
|
|
|
$blessing = array_merge(Arr::except(config('app'), ['key', 'providers', 'aliases', 'cipher', 'log', 'url']), [
|
|
|
|
'baseUrl' => url('/'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$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
|
|
|
|
$this->app->singleton('cipher', "App\Services\Cipher\\".config('secure.cipher'));
|
|
|
|
$this->app->singleton('users', \App\Services\Repositories\UserRepository::class);
|
2016-08-28 10:05:21 +08:00
|
|
|
}
|
|
|
|
}
|