Completed
Push — master ( b2199f...5f83dd )
by Avtandil
02:43
created

MultiLangServiceProvider::provides()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 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
18
class MultiLangServiceProvider extends ServiceProvider
19
{
20
    /**
21
     * Indicates if loading of the provider is deferred.
22
     *
23
     * @var bool
24
     */
25
    protected $defer = false;
26
27
    /**
28
     * Bootstrap any application services.
29
     *
30
     * @return void
31
     */
32 33
    public function boot()
33
    {
34
35
        /*\Route::get(
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% 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...
36
            \Config::get('multilang.text-route.route'),
37
            \Config::get('multilang.text-route.controller') . '@index'
38
        );
39
        \Route::post(
40
            \Config::get('multilang.text-route.route'),
41
            \Config::get('multilang.text-route.controller') . '@save'
42
        );*/
43
44
        // Publish config files
45 33
        $this->publishes([
46 33
            __DIR__ . '/../config/config.php' => config_path('multilang.php'),
47 33
            __DIR__ . '/../views' => base_path('resources/views/vendor/multilang'),
48 33
        ]);
49
50
        // Append the country settings
51 33
        $this->mergeConfigFrom(
52 33
            __DIR__ . '/../config/config.php',
53
            'multilang'
54 33
        );
55
56
        // Register blade directives
57
        Blade::directive('t', function ($expression) {
58
            return "<?php echo e(t({$expression})); ?>";
59 33
        });
60
61
        $this->app['events']->listen('locale.changed', function ($locale) {
62 1
            $this->app['multilang']->setLocale($locale);
63 33
        });
64
65 33
        $this->loadViewsFrom(__DIR__ . '/../views', 'multilang');
66
67
        /*$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...
68
69
    dump($this->app['router']);
70
    die();
71
    });*/
72 33
    }
73
74
    /**
75
     * Register any application services.
76
     *
77
     * @return void
78
     */
79 33
    public function register()
80
    {
81 33
        $configPath = __DIR__ . '/../config/config.php';
82 33
        $this->mergeConfigFrom($configPath, 'debugbar');
83
84
        $this->app->singleton('multilang', function ($app) {
85 4
            $environment = $app->environment();
86 4
            $config = $app['config']->get('multilang');
87
88 4
            $multilang = new \Longman\LaravelMultiLang\MultiLang(
89 4
                $environment,
90 4
                $config,
91 4
                $app['cache'],
92 4
                $app['db']
93 4
            );
94
95 4
            if ($multilang->autoSaveIsAllowed()) {
96
                $app->terminating(function () use ($multilang) {
97
                    return $multilang->saveTexts();
98
                });
99
            }
100
101 4
            return $multilang;
102 33
        });
103
104 33
        $this->app->alias('multilang', 'Longman\LaravelMultiLang\MultiLang');
105
106 33
        $this->app['command.multilang.migration'] = $this->app->share(
107
            function () {
108
                return new MigrationCommand();
109
            }
110 33
        );
111
112 33
        $this->app['command.multilang.texts'] = $this->app->share(
113
            function () {
114
                return new TextsCommand();
115
            }
116 33
        );
117
118 33
        $this->commands(['command.multilang.migration', 'command.multilang.texts']);
119 33
    }
120
121
    /**
122
     * Get the services provided by the provider.
123
     *
124
     * @return array
125
     */
126 3
    public function provides()
127
    {
128
        return [
129 3
            'multilang', 'command.multilang.migration',
130 3
            'command.multilang.texts', 'Longman\LaravelMultiLang\MultiLang',
131 3
        ];
132
    }
133
}
134