GridViewServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
c 2
b 0
f 0
dl 0
loc 15
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Itstructure\GridView;
4
5
use Illuminate\Support\Facades\Blade;
6
use Illuminate\Support\ServiceProvider;
7
use Itstructure\GridView\Commands\PublishCommand;
8
9
/**
10
 * Class GridViewServiceProvider
11
 * @package Itstructure\GridView
12
 */
13
class GridViewServiceProvider extends ServiceProvider
14
{
15
    public function register()
16
    {
17
        $this->registerCommands();
18
    }
19
20
    public function boot()
21
    {
22
        // Loading settings
23
        $this->loadViews();
24
        $this->loadTranslations();
25
26
        // Publish settings
27
        $this->publishViews();
28
        $this->publishTranslations();
29
30
        // Directives
31
        require_once __DIR__ . '/functions.php';
32
33
        Blade::directive('gridView', function ($config) {
34
            return "<?php echo grid_view($config); ?>";
35
        });
36
    }
37
38
39
    /*
40
    |--------------------------------------------------------------------------
41
    | COMMAND SETTINGS
42
    |--------------------------------------------------------------------------
43
    */
44
45
    /**
46
     * Register commands.
47
     * @return void
48
     */
49
    private function registerCommands(): void
50
    {
51
        $this->commands(PublishCommand::class);
52
    }
53
54
55
    /*
56
    |--------------------------------------------------------------------------
57
    | LOADING SETTINGS
58
    |--------------------------------------------------------------------------
59
    */
60
61
    /**
62
     * Set directory to load views.
63
     * @return void
64
     */
65
    private function loadViews(): void
66
    {
67
        $this->loadViewsFrom($this->packagePath('resources/views'), 'grid_view');
68
    }
69
70
    /**
71
     * Set directory to load translations.
72
     * @return void
73
     */
74
    private function loadTranslations(): void
75
    {
76
        $this->loadTranslationsFrom($this->packagePath('resources/lang'), 'grid_view');
77
    }
78
79
80
    /*
81
    |--------------------------------------------------------------------------
82
    | PUBLISH SETTINGS
83
    |--------------------------------------------------------------------------
84
    */
85
86
    /**
87
     * Publish views.
88
     * @return void
89
     */
90
    private function publishViews(): void
91
    {
92
        $this->publishes([
93
            $this->packagePath('resources/views') => resource_path('views/vendor/grid_view'),
94
        ], 'views');
95
    }
96
97
    /**
98
     * Publish translations.
99
     * @return void
100
     */
101
    private function publishTranslations(): void
102
    {
103
        $this->publishes([
104
            $this->packagePath('resources/lang') => resource_path('lang/vendor/grid_view'),
105
        ], 'lang');
106
    }
107
108
109
    /*
110
    |--------------------------------------------------------------------------
111
    | OTHER SETTINGS
112
    |--------------------------------------------------------------------------
113
    */
114
115
    /**
116
     * @param $path
117
     * @return string
118
     */
119
    private function packagePath($path): string
120
    {
121
        return __DIR__ . "/../" . $path;
122
    }
123
}
124