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

MultiLangServiceProvider::boot()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1.0019

Importance

Changes 3
Bugs 2 Features 0
Metric Value
c 3
b 2
f 0
dl 0
loc 25
ccs 7
cts 8
cp 0.875
rs 8.8571
cc 1
eloc 7
nc 1
nop 0
crap 1.0019
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