Completed
Push — master ( dfb849...704c19 )
by Sebastian
04:14
created

LocaleServiceProvider::provides()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace App\Services\Locale;
4
5
use Illuminate\Support\ServiceProvider;
6
use Illuminate\Translation\Translator;
7
8
class LocaleServiceProvider extends ServiceProvider
9
{
10
    public function register()
11
    {
12
        $this->app->singleton(CurrentLocale::class);
13
        $this->app->alias(CurrentLocale::class, 'currentLocale');
14
15
        $this->registerLoader();
16
17
        $this->app->singleton('translator', function ($app) {
18
            $loader = $app['translation.loader'];
19
20
            $locale = $app['config']['app.locale'];
21
22
            $trans = new Translator($loader, $locale);
23
24
            $trans->setFallback($app['config']['app.fallback_locale']);
25
26
            return $trans;
27
        });
28
    }
29
30
    protected function registerLoader()
31
    {
32
        $this->app->singleton('translation.loader', function ($app) {
33
            return new TranslationLoader($app['files'], $app['path.lang']);
34
        });
35
    }
36
37
    public function provides(): array
38
    {
39
        return ['translator', 'translation.loader'];
40
    }
41
}
42