Test Failed
Push — master ( ffdf4e...19cafa )
by Avtandil
04:06
created

MultiLangServiceProvider::provides()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 11
ccs 0
cts 0
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
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\ExportCommand;
17
use Longman\LaravelMultiLang\Console\ImportCommand;
18
use Longman\LaravelMultiLang\Console\MigrationCommand;
19
use Longman\LaravelMultiLang\Console\TextsCommand;
20
21
class MultiLangServiceProvider extends ServiceProvider
22
{
23
    /**
24
     * Indicates if loading of the provider is deferred.
25
     *
26
     * @var bool
27
     */
28
    protected $defer = false;
29
30
    /**
31
     * Bootstrap any application services.
32
     *
33
     * @return void
34
     */
35
    public function boot()
36
    {
37
        // Publish config files
38
        $this->publishes(
39
            [
40
                __DIR__ . '/../config/config.php' => config_path('multilang.php'),
41
                __DIR__ . '/../views'             => base_path('resources/views/vendor/multilang'),
42
            ]
43
        );
44
45
        // Append the country settings
46
        $this->mergeConfigFrom(
47
            __DIR__ . '/../config/config.php',
48
            'multilang'
49
        );
50
51
        // Register blade directives
52
        Blade::directive('t', function ($expression) {
53
            return "<?php echo e(t({$expression})); ?>";
54
        });
55
56
        $this->app['events']->listen(RouteMatched::class, function () {
57
            $scope = $this->app['config']->get('app.scope');
58
            if ($scope && $scope != 'global') {
59
                $this->app['multilang']->setScope($scope);
60
            }
61
            $this->app['multilang']->setLocale($this->app->getLocale());
62
        });
63
64
        $this->loadViewsFrom(__DIR__ . '/../views', 'multilang');
65
    }
66
67
    /**
68
     * Register any application services.
69
     *
70
     * @return void
71
     */
72 42
    public function register()
73
    {
74 42
        $configPath = __DIR__ . '/../config/config.php';
75 42
        $this->mergeConfigFrom($configPath, 'debugbar');
76
77
        $this->app->singleton('multilang', function ($app) {
78
            $environment = $app->environment();
79
            $config      = $app['config']->get('multilang');
80
81
            $multilang = new \Longman\LaravelMultiLang\MultiLang(
82
                $environment,
83
                $config,
84
                $app['cache'],
85
                $app['db']
86
            );
87
88
            if ($multilang->autoSaveIsAllowed()) {
89
                $app->terminating(function () use ($multilang) {
90
                    $scope = $this->app['config']->get('app.scope');
91
                    if ($scope && $scope != 'global') {
92
                        $multilang->setScope($scope);
93
                    }
94
                    return $multilang->saveTexts();
95
                });
96
            }
97
98
            return $multilang;
99 42
        });
100
101 42
        $this->app->alias('multilang', 'Longman\LaravelMultiLang\MultiLang');
102
103 42
        $this->app['command.multilang.migration'] = $this->app->singletone(
0 ignored issues
show
Bug introduced by
The method singletone() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean singleton()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
104
            function () {
105
                return new MigrationCommand();
106
            }
107
        );
108
109
        $this->app['command.multilang.texts'] = $this->app->singletone(
0 ignored issues
show
Bug introduced by
The method singletone() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean singleton()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
110
            function () {
111
                return new TextsCommand();
112
            }
113
        );
114
115
        $this->app['command.multilang.import'] = $this->app->singletone(
0 ignored issues
show
Bug introduced by
The method singletone() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean singleton()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
116
            function () {
117
                return new ImportCommand();
118
            }
119
        );
120
121
        $this->app['command.multilang.export'] = $this->app->singletone(
0 ignored issues
show
Bug introduced by
The method singletone() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean singleton()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
122
            function () {
123
                return new ExportCommand();
124
            }
125
        );
126
127
        $this->commands(
128
            [
129
                'command.multilang.migration',
130
                'command.multilang.texts',
131
                'command.multilang.import',
132
                'command.multilang.export',
133
            ]
134
        );
135
    }
136
137
    /**
138
     * Get the services provided by the provider.
139
     *
140
     * @return array
141
     */
142
    public function provides()
143
    {
144
        return [
145
            'multilang',
146
            'command.multilang.migration',
147
            'command.multilang.texts',
148
            'command.multilang.import',
149
            'command.multilang.export',
150
            'Longman\LaravelMultiLang\MultiLang',
151
        ];
152
    }
153
}
154