Completed
Push — master ( 12d899...a33b7a )
by Avtandil
04:40
created

MultiLangServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 91.11%

Importance

Changes 11
Bugs 6 Features 1
Metric Value
c 11
b 6
f 1
dl 0
loc 110
ccs 41
cts 45
cp 0.9111
rs 10
wmc 4
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
B boot() 0 34 1
B register() 0 41 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\Support\ServiceProvider;
15
use Longman\LaravelMultiLang\Console\MigrationCommand;
16
use Longman\LaravelMultiLang\Console\TextsCommand;
17
use Route;
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
     * Bootstrap any application services.
30
     *
31
     * @return void
32
     */
33 37
    public function boot()
34
    {
35
36
        // Publish config files
37 37
        $this->publishes([
38 37
            __DIR__ . '/../config/config.php' => config_path('multilang.php'),
39 37
            __DIR__ . '/../views' => base_path('resources/views/vendor/multilang'),
40 37
        ]);
41
42
        // Append the country settings
43 37
        $this->mergeConfigFrom(
44 37
            __DIR__ . '/../config/config.php',
45
            'multilang'
46 37
        );
47
48
        // Register blade directives
49
        Blade::directive('t', function ($expression) {
50
            return "<?php echo e(t({$expression})); ?>";
51 37
        });
52
53
        $this->app['events']->listen('locale.changed', function ($locale) {
54 1
            $this->app['multilang']->setLocale($locale);
55 37
        });
56
57
58 37
        $this->loadViewsFrom(__DIR__ . '/../views', 'multilang');
59
60
        /*
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...
61
        $this->app['events']->listen(RouteMatched::class, function () {
62
        dump($this->app['router']);
63
        die();
64
        });
65
        */
66 37
    }
67
68
69
    /**
70
     * Register any application services.
71
     *
72
     * @return void
73
     */
74 37
    public function register()
75
    {
76 37
        $configPath = __DIR__ . '/../config/config.php';
77 37
        $this->mergeConfigFrom($configPath, 'debugbar');
78
79
        $this->app->singleton('multilang', function ($app) {
80 4
            $environment = $app->environment();
81 4
            $config = $app['config']->get('multilang');
82
83 37
            $multilang = new \Longman\LaravelMultiLang\MultiLang(
84 4
                $environment,
85 4
                $config,
86 4
                $app['cache'],
87 4
                $app['db']
88 4
            );
89
90 4
            if ($multilang->autoSaveIsAllowed()) {
91
                $app->terminating(function () use ($multilang) {
92
                    return $multilang->saveTexts();
93
                });
94
            }
95
96 4
            return $multilang;
97 37
        });
98
99 37
        $this->app->alias('multilang', 'Longman\LaravelMultiLang\MultiLang');
100
101 37
        $this->app['command.multilang.migration'] = $this->app->share(
102
            function () {
103 4
                return new MigrationCommand();
104
            }
105 37
        );
106
107 37
        $this->app['command.multilang.texts'] = $this->app->share(
108 4
            function () {
109 4
                return new TextsCommand();
110
            }
111 37
        );
112
113 37
        $this->commands(['command.multilang.migration', 'command.multilang.texts']);
114 37
    }
115
116
    /**
117
     * Get the services provided by the provider.
118
     *
119
     * @return array
120
     */
121 3
    public function provides()
122
    {
123
        return [
124 3
            'multilang', 'command.multilang.migration',
125 3
            'command.multilang.texts', 'Longman\LaravelMultiLang\MultiLang',
126 3
        ];
127
    }
128
}
129