|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Providers; |
|
4
|
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
|
6
|
|
|
use Illuminate\Support\ServiceProvider; |
|
7
|
|
|
|
|
8
|
|
|
class AppServiceProvider extends ServiceProvider |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Bootstrap any application services. |
|
12
|
|
|
*/ |
|
13
|
1 |
|
public function boot() |
|
14
|
|
|
{ |
|
15
|
1 |
|
Carbon::setLocale('zh'); |
|
16
|
1 |
|
} |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Register any application services. |
|
20
|
|
|
*/ |
|
21
|
1 |
|
public function register() |
|
22
|
|
|
{ |
|
23
|
1 |
|
if (is_domain('admin')) { |
|
24
|
|
|
$this->registerServices($this->getProvidersForAdminSite()); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
1 |
|
if (is_domain('api')) { |
|
28
|
|
|
$this->addAcceptableJsonType(); |
|
29
|
|
|
} |
|
30
|
1 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Register services. |
|
34
|
|
|
* |
|
35
|
|
|
* @param string|array $services |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function registerServices($services) |
|
38
|
|
|
{ |
|
39
|
|
|
array_map([$this->app, 'register'], (array) $services); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Get the services provided for admin site. |
|
44
|
|
|
* |
|
45
|
|
|
* @return array |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function getProvidersForAdminSite() |
|
48
|
|
|
{ |
|
49
|
|
|
return [ |
|
50
|
|
|
'Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider', |
|
51
|
|
|
]; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Add "application/json" to the "Accept" header for the current request, |
|
56
|
|
|
* it will make `$request->expectsJson()` return true. |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function addAcceptableJsonType() |
|
59
|
|
|
{ |
|
60
|
|
|
$this->app->rebinding('request', function ($app, $request) { |
|
61
|
|
|
if (! str_contains(($accept = $request->header('Accept')), ['/json', '+json'])) { |
|
62
|
|
|
$accept = rtrim('application/json,'.$accept, ','); |
|
63
|
|
|
|
|
64
|
|
|
$request->headers->set('Accept', $accept); |
|
65
|
|
|
$request->server->set('HTTP_ACCEPT', $accept); |
|
66
|
|
|
} |
|
67
|
|
|
}); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|