Completed
Push — master ( 0eceaa...aee3a6 )
by Ben
15:21 queued 05:47
created

LocaleServiceProvider::getConfigValues()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 8
ccs 0
cts 4
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Thinktomorrow\Locale;
4
5
use Illuminate\Support\ServiceProvider;
6
use Thinktomorrow\Locale\Parsers\RouteParser;
7
use Thinktomorrow\Locale\Parsers\UrlParser;
8
use Thinktomorrow\Locale\Values\Config;
9
10
class LocaleServiceProvider extends ServiceProvider
11
{
12 66
    public function register()
13
    {
14 66
        require_once __DIR__.'/helpers.php';
15
16 66
        $this->publishes([
17 66
            __DIR__.'/config/locale.php' => config_path('thinktomorrow/locale.php'),
18
        ]);
19
20 66
        $this->mergeConfigFrom(
21 66
            __DIR__.'/config/locale.php', 'thinktomorrow.locale'
22
        );
23
24 66
        $this->app->singleton(Detect::class, function ($app) {
25
            return new Detect($app['request'], Config::from($this->getConfigValues()));
26 66
        });
27
28 66
        $this->app->singleton(UrlParser::class, function ($app) {
29 63
            return new UrlParser(
30 63
                $app['Illuminate\Contracts\Routing\UrlGenerator']
31
            );
32 66
        });
33
34 66
        $this->app->singleton(RouteParser::class, function ($app) {
35 63
            return new RouteParser(
36 63
                $app['Thinktomorrow\Locale\Parsers\UrlParser'],
37 63
                $app['translator']
38
            );
39 66
        });
40
41 66
        $this->app->singleton(LocaleUrl::class, function ($app) {
42
            return new LocaleUrl(
43
                $app['Thinktomorrow\Locale\Detect'],
44
                $app['Thinktomorrow\Locale\Parsers\UrlParser'],
45
                $app['Thinktomorrow\Locale\Parsers\RouteParser'],
46
                Config::from($this->getConfigValues())
47
            );
48 66
        });
49
50
        /*
51
         * Facade for getting current active scope
52
         */
53 66
        $this->app->singleton('tt-locale-scope', function ($app) {
54 8
            return $app->make(Detect::class)->detectLocale()->getScope();
55 66
        });
56 66
    }
57
58
    private function getConfigValues()
59
    {
60
        if (file_exists(config_path('thinktomorrow/locale.php'))) {
61
            return require config_path('thinktomorrow/locale.php');
62
        }
63
64
        return require __DIR__.'/config/locale.php';
65
    }
66
}
67