ViewLocalizationServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * @link https://github.com/vuongxuongminh/laravel-view-localization
4
 *
5
 * @copyright (c) Vuong Xuong Minh
6
 * @license [MIT](https://opensource.org/licenses/MIT)
7
 */
8
9
namespace VXM\ViewLocalization;
10
11
use Illuminate\Support\ServiceProvider;
12
13
/**
14
 * @author Vuong Minh <[email protected]>
15
 * @since  1.0.0
16
 */
17
class ViewLocalizationServiceProvider extends ServiceProvider
18
{
19
    /**
20
     * Boot package services.
21
     */
22
    public function boot(): void
23
    {
24
        $this->publishConfigs();
25
        $this->registerViewComposeListener();
26
    }
27
28
    /**
29
     * Publish package config files.
30
     */
31
    protected function publishConfigs(): void
32
    {
33
        $this->publishes([
34
            __DIR__.'/../config/viewlocalization.php' => config_path('viewlocalization.php'),
35
        ], 'config');
36
    }
37
38
    /**
39
     * Register view compose event listener
40
     */
41
    protected function registerViewComposeListener(): void
42
    {
43
        $this->app['view']->composer('*', ViewComposer::class);
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function register(): void
50
    {
51
        $this->mergeDefaultConfigs();
52
        $this->registerServices();
53
    }
54
55
    /**
56
     * Merge default package configs.
57
     */
58
    protected function mergeDefaultConfigs(): void
59
    {
60
        $this->mergeConfigFrom(__DIR__.'/../config/viewlocalization.php', 'viewlocalization');
61
    }
62
63
    /**
64
     * Register package services.
65
     */
66
    protected function registerServices(): void
67
    {
68
        $this->app->singleton(ViewComposer::class, function ($app) {
69
            return new ViewComposer($app, $app['config']->get['viewlocalization.sourceLocale'], $app['files']);
70
        });
71
    }
72
}
73