Completed
Push — master ( d9d3da...1bdf99 )
by Avtandil
02:31
created

MultiLangServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 82.05%

Importance

Changes 5
Bugs 4 Features 0
Metric Value
wmc 4
c 5
b 4
f 0
lcom 1
cbo 5
dl 0
loc 103
ccs 32
cts 39
cp 0.8205
rs 10

3 Methods

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