RbacServiceProvider::publishViews()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Itstructure\LaRbac;
4
5
use Illuminate\Support\Facades\View;
6
use Illuminate\Support\ServiceProvider;
7
use Itstructure\LaRbac\Commands\{PublishCommand, DatabaseCommand, AdminCommand};
8
use Itstructure\GridView\GridViewServiceProvider;
9
use Itstructure\GridView\Grid;
10
11
/**
12
 * Class RbacServiceProvider
13
 *
14
 * @package Itstructure\LaRbac
15
 *
16
 * @author Andrey Girnik <[email protected]>
17
 */
18
class RbacServiceProvider extends ServiceProvider
19
{
20
    public function register()
21
    {
22
        $this->app->register(RbacRouteServiceProvider::class);
23
        $this->app->register(RbacAuthServiceProvider::class);
24
        $this->app->register(GridViewServiceProvider::class);
25
26
        $this->registerCommands();
27
    }
28
29
    public function boot()
30
    {
31
        // Loading settings
32
        $this->loadViews();
33
        $this->loadTranslations();
34
        $this->loadMigrations();
35
36
37
        // Publish settings
38
        $this->publishConfig();
39
        $this->publishViews();
40
        $this->publishTranslations();
41
        $this->publishMigrations();
42
        $this->publishSeeders();
43
44
45
        // Global view's params
46
        View::share('rbacLayout', config('rbac.layout'));
47
        View::share('rbacRowsPerPage', config('rbac.rowsPerPage', Grid::INIT_ROWS_PER_PAGE));
48
    }
49
50
51
    /*
52
    |--------------------------------------------------------------------------
53
    | COMMAND SETTINGS
54
    |--------------------------------------------------------------------------
55
    */
56
57
    /**
58
     * Register commands.
59
     * @return void
60
     */
61
    private function registerCommands(): void
62
    {
63
        $this->commands(PublishCommand::class);
64
        $this->commands(DatabaseCommand::class);
65
        $this->commands(AdminCommand::class);
66
    }
67
68
69
    /*
70
    |--------------------------------------------------------------------------
71
    | LOADING SETTINGS
72
    |--------------------------------------------------------------------------
73
    */
74
75
    /**
76
     * Set directory to load views.
77
     * @return void
78
     */
79
    private function loadViews(): void
80
    {
81
        $this->loadViewsFrom($this->packagePath('resources/views'), 'rbac');
82
    }
83
84
    /**
85
     * Set directory to load translations.
86
     * @return void
87
     */
88
    private function loadTranslations(): void
89
    {
90
        $this->loadTranslationsFrom($this->packagePath('resources/lang'), 'rbac');
91
    }
92
93
    /**
94
     * Set directory to load migrations.
95
     * @return void
96
     */
97
    private function loadMigrations(): void
98
    {
99
        $this->loadMigrationsFrom($this->packagePath('database/migrations'));
100
    }
101
102
103
    /*
104
    |--------------------------------------------------------------------------
105
    | PUBLISH SETTINGS
106
    |--------------------------------------------------------------------------
107
    */
108
109
    /**
110
     * Publish config.
111
     * @return void
112
     */
113
    private function publishConfig(): void
114
    {
115
        $configPath = $this->packagePath('config/rbac.php');
116
117
        $this->publishes([
118
            $configPath => config_path('rbac.php'),
119
        ], 'config');
120
121
        $this->mergeConfigFrom($configPath, 'rbac');
122
    }
123
124
    /**
125
     * Publish views.
126
     * @return void
127
     */
128
    private function publishViews(): void
129
    {
130
        $this->publishes([
131
            $this->packagePath('resources/views') => resource_path('views/vendor/rbac'),
132
        ], 'views');
133
    }
134
135
    /**
136
     * Publish translations.
137
     * @return void
138
     */
139
    private function publishTranslations(): void
140
    {
141
        $this->publishes([
142
            $this->packagePath('resources/lang') => resource_path('lang/vendor/rbac'),
143
        ], 'lang');
144
    }
145
146
    /**
147
     * Publish migrations.
148
     * @return void
149
     */
150
    private function publishMigrations(): void
151
    {
152
        $this->publishes([
153
            $this->packagePath('database/migrations') => database_path('migrations'),
154
        ], 'migrations');
155
    }
156
157
    /**
158
     * Publish seeders.
159
     * @return void
160
     */
161
    private function publishSeeders(): void
162
    {
163
        $this->publishes([
164
            $this->packagePath('database/seeders') => database_path('seeders'),
165
        ], 'seeders');
166
    }
167
168
169
    /*
170
    |--------------------------------------------------------------------------
171
    | OTHER SETTINGS
172
    |--------------------------------------------------------------------------
173
    */
174
175
    /**
176
     * Get package path.
177
     * @param $path
178
     * @return string
179
     */
180
    private function packagePath($path): string
181
    {
182
        return __DIR__ . "/../" . $path;
183
    }
184
}
185