Completed
Push — master ( 1bdf99...49cc2f )
by Avtandil
02:51
created

MultiLangServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 96.77%

Importance

Changes 6
Bugs 4 Features 0
Metric Value
wmc 4
c 6
b 4
f 0
lcom 1
cbo 5
dl 0
loc 108
ccs 30
cts 31
cp 0.9677
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B boot() 0 30 1
B register() 0 42 2
A provides() 0 7 1
1
<?php
2
/*
3
 * This file is part of the Laravel MultiLang package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\LaravelMultiLang;
12
13
use Blade;
14
use Illuminate\Routing\Events\RouteMatched;
15
use Illuminate\Support\ServiceProvider;
16
use Longman\LaravelMultiLang\Console\MigrationCommand;
17
use Longman\LaravelMultiLang\Console\TextsCommand;
18
19
class MultiLangServiceProvider extends ServiceProvider
20
{
21
    /**
22
     * Indicates if loading of the provider is deferred.
23
     *
24
     * @var bool
25
     */
26
    protected $defer = false;
27
28
29
    /**
30
     * Bootstrap any application services.
31
     *
32
     * @return void
33
     */
34 33
    public function boot()
35
    {
36
37
        // Publish config files
38 33
        $this->publishes([__DIR__ . '/../config/config.php' => config_path('multilang.php')]);
39
40
        // Append the country settings
41 33
        $this->mergeConfigFrom(
42 33
            __DIR__ . '/../config/config.php',
43 33
            'multilang'
44
        );
45
46
        // Register blade directives
47
        Blade::directive('t', function ($expression) {
48
            return "<?php echo e(t({$expression})); ?>";
49 33
        });
50
51
        $this->app['events']->listen('locale.changed', function ($locale) {
52 1
            $this->app['multilang']->setLocale($locale);
53 33
        });
54
55
56
        /*$this->app['events']->listen(RouteMatched::class, function () {
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
57
58
            dump($this->app['router']);
59
            die();
60
        });*/
61
62
63 33
    }
64
65
    /**
66
     * Register any application services.
67
     *
68
     * @return void
69
     */
70 33
    public function register()
71
    {
72 33
        $configPath = __DIR__ . '/../config/config.php';
73 33
        $this->mergeConfigFrom($configPath, 'debugbar');
74
75
        $this->app->singleton('multilang', function ($app) {
76 4
            $environment = $app->environment();
77 4
            $config = $app['config']->get('multilang');
78
79 4
            $multilang = new \Longman\LaravelMultiLang\MultiLang(
80
                $environment,
81
                $config,
82 4
                $app['cache'],
83 4
                $app['db']
84
            );
85
86 4
            if ($multilang->autoSaveIsAllowed()) {
87
                $app->terminating(function () use ($multilang) {
88
                    return $multilang->saveTexts();
89
                });
90
            }
91
92 4
            return $multilang;
93 33
        });
94
95 33
        $this->app->alias('multilang', 'Longman\LaravelMultiLang\MultiLang');
96
97 33
        $this->app['command.multilang.migration'] = $this->app->share(
98
            function () {
99
                return new MigrationCommand();
100 33
            }
101
        );
102
103 33
        $this->app['command.multilang.texts'] = $this->app->share(
104 33
            function () {
105
                return new TextsCommand();
106 33
            }
107
        );
108
109 33
        $this->commands(['command.multilang.migration', 'command.multilang.texts']);
110
111 33
    }
112
113
    /**
114
     * Get the services provided by the provider.
115
     *
116
     * @return array
117
     */
118 3
    public function provides()
119
    {
120
        return [
121 3
            'multilang', 'command.multilang.migration',
122
            'command.multilang.texts', 'Longman\LaravelMultiLang\MultiLang'
123
        ];
124
    }
125
126
}
127