Completed
Push — master ( 1b7c9c...cf42d1 )
by Avtandil
03:25
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 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
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 Illuminate\Support\ServiceProvider;
14
use Longman\LaravelMultiLang\Console\MigrationCommand;
15
use Longman\LaravelMultiLang\Console\TextsCommand;
16
use Blade;
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
    /**
29
     * Bootstrap any application services.
30
     *
31
     * @return void
32
     */
33 31
    public function boot()
34
    {
35
36
        // Publish config files
37 31
        $this->publishes([__DIR__ . '/../config/config.php' => config_path('multilang.php')]);
38
39
        // Append the country settings
40 31
        $this->mergeConfigFrom(
41 31
            __DIR__ . '/../config/config.php',
42
            'multilang'
43 31
        );
44
45
        // Register blade directives
46
        Blade::directive('t', function ($expression) {
47
            return "<?php echo e(t({$expression})); ?>";
48 31
        });
49
50 31
    }
51
52
    /**
53
     * Register any application services.
54
     *
55
     * @return void
56
     */
57 31
    public function register()
58
    {
59 31
        $configPath = __DIR__ . '/../config/config.php';
60 31
        $this->mergeConfigFrom($configPath, 'debugbar');
61
62
        $this->app->singleton('multilang', function ($app) {
63 1
            $locale = $app->getLocale();
64 1
            $environment = $app->environment();
65 31
            $config = $app['config']->get('multilang');
66
67 31
            $multilang = new \Longman\LaravelMultiLang\MultiLang(
68 1
                $environment,
69 1
                $config,
70 1
                $app['cache'],
71 1
                $app['db']
72 1
            );
73
74 1
            $multilang->setLocale($locale);
75
76 1
            if ($multilang->autoSaveIsAllowed()) {
77
                $this->app->terminating(function () use ($multilang) {
78
                    return $multilang->saveTexts();
79
                });
80
            }
81
82 1
            return $multilang;
83 31
        });
84
85 31
        $this->app->alias('multilang', 'Longman\LaravelMultiLang\MultiLang');
86
87 31
        $this->app['command.multilang.migration'] = $this->app->share(
88
            function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
89
                return new MigrationCommand();
90
            }
91 31
        );
92
93 31
        $this->app['command.multilang.texts'] = $this->app->share(
94
            function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
95
                return new TextsCommand();
96
            }
97 31
        );
98
99 31
        $this->commands(['command.multilang.migration', 'command.multilang.texts']);
100
101 31
    }
102
103
    /**
104
     * Get the services provided by the provider.
105
     *
106
     * @return array
107
     */
108 3
    public function provides()
109
    {
110
        return [
111 3
            'multilang', 'command.multilang.migration',
112 3
            'command.multilang.texts', 'Longman\LaravelMultiLang\MultiLang'
113 3
        ];
114
    }
115
116
}
117