|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of laravel.su package. |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
declare(strict_types=1); |
|
10
|
|
|
|
|
11
|
|
|
namespace App\Providers; |
|
12
|
|
|
|
|
13
|
|
|
use App\Services\NavMatcher; |
|
14
|
|
|
use Carbon\Carbon; |
|
15
|
|
|
use App\Services\ColorGenerator; |
|
16
|
|
|
use GuzzleHttp\Client as Guzzle; |
|
17
|
|
|
use Illuminate\Config\Repository; |
|
18
|
|
|
use App\GraphQL\Kernel\EnumTransfer; |
|
19
|
|
|
use Illuminate\Contracts\Container\Container; |
|
20
|
|
|
use Illuminate\Foundation\Application; |
|
21
|
|
|
use Illuminate\Routing\Router; |
|
22
|
|
|
use Illuminate\Support\ServiceProvider; |
|
23
|
|
|
use GuzzleHttp\ClientInterface as GuzzleInterface; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class AppServiceProvider. |
|
27
|
|
|
*/ |
|
28
|
|
|
class AppServiceProvider extends ServiceProvider |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var Application |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $app; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @retrun void |
|
37
|
|
|
*/ |
|
38
|
|
|
public function register(): void |
|
39
|
|
|
{ |
|
40
|
|
|
$this->localizeCarbon(); |
|
41
|
|
|
$this->loadLocalProviders(); |
|
42
|
|
|
$this->registerGuzzleClient(); |
|
43
|
|
|
|
|
44
|
|
|
$this->app->singleton(ColorGenerator::class); |
|
45
|
|
|
$this->app->singleton(EnumTransfer::class); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @return void |
|
50
|
|
|
*/ |
|
51
|
|
|
public function boot(): void |
|
52
|
|
|
{ |
|
53
|
|
|
$this->app->singleton(NavMatcher::class, function (Container $app) { |
|
54
|
|
|
$route = $app->make(Router::class)->current(); |
|
55
|
|
|
|
|
56
|
|
|
return new NavMatcher($route); |
|
57
|
|
|
}); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
private function localizeCarbon(): void |
|
61
|
|
|
{ |
|
62
|
|
|
$locale = $this->app->make(Repository::class)->get('app.locale'); |
|
63
|
|
|
|
|
64
|
|
|
Carbon::setLocale($locale); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
private function loadLocalProviders(): void |
|
68
|
|
|
{ |
|
69
|
|
|
if ($this->app->isLocal()) { |
|
70
|
|
|
array_map( |
|
71
|
|
|
[$this->app, 'register'], |
|
72
|
|
|
config('app.local_providers', []) |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
private function registerGuzzleClient(): void |
|
78
|
|
|
{ |
|
79
|
|
|
$this->app->singleton(Guzzle::class, function () { |
|
80
|
|
|
return new Guzzle(); |
|
81
|
|
|
}); |
|
82
|
|
|
|
|
83
|
|
|
$this->app->alias(Guzzle::class, GuzzleInterface::class); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|