Completed
Push — master ( 488702...18fedf )
by Stéphane
22:05
created

ServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 79.31%

Importance

Changes 0
Metric Value
dl 0
loc 59
ccs 23
cts 29
cp 0.7931
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A registerManager() 0 10 1
A registerLanguageChangeRoute() 0 13 2
A register() 0 6 1
A provides() 0 4 1
A boot() 0 6 1
1
<?php namespace Rocket\Translation\Support\Laravel5;
2
3
use Illuminate\Foundation\Application;
4
use Rocket\Translation\Commands\GenerateFiles;
5
6
class ServiceProvider extends \Illuminate\Support\ServiceProvider
7
{
8 216
    protected function registerManager()
9
    {
10 216
        $this->app->alias('i18n', \Rocket\Translation\I18NInterface::class);
11
        $this->app->singleton(
12 177
            'i18n',
13
            function (Application $app) {
14 216
                return $app->make(\Rocket\Translation\I18N::class);
15 216
            }
16
        );
17 216
    }
18
19 216
    protected function registerLanguageChangeRoute()
20 216
    {
21
        $this->app['router']->get(
22
            'lang/{lang}',
23
            function ($lang) {
24
                if (!$this->app['i18n']->setCurrentLanguage($lang)) {
25
                    $this->app['session']->flash('error', t('Cette langue n\'est pas disponible'));
26
                }
27
28 216
                return $this->app['redirect']->back();
29 216
            }
30
        );
31 216
    }
32
33 216
    /**
34 216
     * Register the service provider.
35 216
     *
36 216
     * @return void
37
     */
38 216
    public function register()
39
    {
40 216
        $this->registerManager();
41 216
42
        $this->registerLanguageChangeRoute();
43
    }
44
45
    /**
46
     * Get the services provided by the provider.
47
     *
48 216
     * @return array
49
     */
50 216
    public function provides()
51
    {
52 216
        return ['i18n'];
53
    }
54 216
55 216
    /**
56
     * {@inheritdoc}
57
     */
58
    public function boot()
59
    {
60
        $this->loadMigrationsFrom(__DIR__.'/../../migrations');
61
62
        $this->commands([GenerateFiles::class]);
63
    }
64
}
65