DashboardServiceProvider::boot()   B
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 45
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 26
CRAP Score 3

Importance

Changes 5
Bugs 0 Features 1
Metric Value
c 5
b 0
f 1
dl 0
loc 45
ccs 26
cts 26
cp 1
rs 8.8571
cc 3
eloc 23
nc 4
nop 0
crap 3
1
<?php
2
3
/**
4
 * @package     Dashboard
5
 * @author      Ian Olson <[email protected]>
6
 * @license     MIT
7
 * @copyright   2015, Laraflock
8
 * @link        https://github.com/laraflock
9
 */
10
11
namespace Laraflock\Dashboard\Providers;
12
13
use AdamWathan\BootForms\BootFormsServiceProvider;
14
use AdamWathan\BootForms\Facades\BootForm;
15
use AdamWathan\Form\Facades\Form;
16
use AdamWathan\Form\FormServiceProvider;
17
use Carbon\Carbon;
18
use Cartalyst\Sentinel\Laravel\Facades\Activation;
19
use Cartalyst\Sentinel\Laravel\Facades\Reminder;
20
use Cartalyst\Sentinel\Laravel\Facades\Sentinel;
21
use Cartalyst\Sentinel\Laravel\SentinelServiceProvider;
22
use Illuminate\Foundation\AliasLoader;
23
use Illuminate\Support\ServiceProvider;
24
use Laracasts\Flash\Flash;
25
use Laracasts\Flash\FlashServiceProvider;
26
use Laravelista\Ekko\EkkoServiceProvider;
27
use Laravelista\Ekko\Facades\Ekko;
28
use Laraflock\Dashboard\Commands\FreshCommand;
29
use Laraflock\Dashboard\Commands\InstallerCommand;
30
use Laraflock\Dashboard\Commands\SetupCommand;
31
use Laraflock\Dashboard\Commands\UninstallCommand;
32
use Laraflock\Dashboard\Middleware\UserMiddleware;
33
use Laraflock\Dashboard\Middleware\RoleMiddleware;
34
use Laraflock\Dashboard\Middleware\PermissionMiddleware;
35
36
class DashboardServiceProvider extends ServiceProvider
37
{
38
    /**
39
     * {@inheritDoc}
40
     */
41 110
    public function boot()
42
    {
43
        // Setup Default namespace until config file is published.
44 110
        if (!$namespace = config('laraflock.dashboard.viewNamespace')) {
45 110
            $namespace = 'dashboard';
46 110
        }
47
48
        // Load & Publish views.
49 110
        $this->loadViewsFrom(__DIR__ . '/../Resources/views', $namespace);
50 110
        $this->publishes([
51 110
          __DIR__ . '/../Resources/views' => base_path('resources/views/vendor/' . $namespace),
52 110
        ], 'views');
53
54
        // Load translations.
55 110
        $this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'dashboard');
56
57
        // Publish config.
58 110
        $config = realpath(__DIR__ . '/../config.php');
59
60 110
        $this->mergeConfigFrom($config, 'laraflock.dashboard');
61
62 110
        $this->publishes([
63 110
            $config => config_path('laraflock.dashboard.php'),
64 110
        ], 'config');
65
66
        // Use package routes.
67 110
        if (config('laraflock.dashboard.routes')) {
68 110
            include __DIR__ . '/../routes.php';
69 110
        }
70
71
        // Publish migrations.
72 110
        $migrations = realpath(__DIR__ . '/../Database/Migrations');
73
74 110
        $this->publishes([
75 110
          $migrations => database_path('/migrations'),
76 110
        ], 'migrations');
77
78
        // Publish assets.
79 110
        $this->publishes([
80 110
          __DIR__ . '/../Resources/assets' => public_path('vendor/laraflock'),
81 110
        ], 'public');
82
83
        // Setup interfaces.
84 110
        $this->setupInterfaces();
85 110
    }
86
87
    /**
88
     * {@inheritDoc}
89
     */
90 110
    public function register()
91
    {
92 110
        $this->setupProviders();
93 110
        $this->setupFacades();
94 110
        $this->setupConsoleCommands();
95 110
        $this->setupMiddleware();
96 110
    }
97
98
    /**
99
     * Register the middleware to the application
100
     *
101
     * Register the following middleware:
102
     * - \Laraflock\Dashboard\Middleware\UserMiddleware
103
     * - \Laraflock\Dashboard\Middleware\RoleMiddleware
104
     * - \Laraflock\Dashboard\Middleware\PermissionMiddleware
105
     */
106 110
    protected function setupMiddleware()
107
    {
108 110
        $this->app['router']->middleware('user', UserMiddleware::class);
109 110
        $this->app['router']->middleware('roles', RoleMiddleware::class);
110 110
        $this->app['router']->middleware('permissions', PermissionMiddleware::class);
111 110
    }
112
113
    /**
114
     * Register the providers to the application.
115
     *
116
     * This will register packages that this package is dependent on.
117
     *
118
     * Register the following providers:
119
     * - Sentinel
120
     * - Ekko
121
     * - Flash
122
     * - Form
123
     * - BootForm
124
     */
125 110
    protected function setupProviders()
126
    {
127
        // Register Sentinel Package
128
        // - Used for authentication, authorization, roles, and permissions.
129 110
        $this->app->register(SentinelServiceProvider::class);
130
131
        // Register Ekko Package
132
        // - Used for blade templates to trigger active classes for navigation items.
133 110
        $this->app->register(EkkoServiceProvider::class);
134
135
        // Register Flash Package
136
        // - Used for easy flash session notifications and messages.
137 110
        $this->app->register(FlashServiceProvider::class);
138
139
        // Register Form Package
140
        // - Used for HTML form building with easy and readable API.
141 110
        $this->app->register(FormServiceProvider::class);
142
143
        // Register Bootstrap Form Package
144
        // - Used for HTML form building with easy and readable API (Bootstrap 3).
145 110
        $this->app->register(BootFormsServiceProvider::class);
146 110
    }
147
148
    /**
149
     * Register Interface Bindings
150
     */
151 110
    protected function setupInterfaces()
152
    {
153
        // Bind the Auth Repository Interface
154 110
        $this->app->bind(
155 110
          'Laraflock\Dashboard\Repositories\Auth\AuthRepositoryInterface',
156 110
          config('laraflock.dashboard.authRepositoryClass')
157 110
        );
158
159
        // Bind the Permission Repository Interface
160 110
        $this->app->bind(
161 110
          'Laraflock\Dashboard\Repositories\Permission\PermissionRepositoryInterface',
162 110
          config('laraflock.dashboard.permissionRepositoryClass')
163 110
        );
164
165
        // Bind the Role Repository Interface
166 110
        $this->app->bind(
167 110
          'Laraflock\Dashboard\Repositories\Role\RoleRepositoryInterface',
168 110
          config('laraflock.dashboard.roleRepositoryClass')
169 110
        );
170
171
        // Bind the User Repository Interface
172 110
        $this->app->bind(
173 110
          'Laraflock\Dashboard\Repositories\User\UserRepositoryInterface',
174 110
          config('laraflock.dashboard.userRepositoryClass')
175 110
        );
176
177
        // Bind the Module Repository Interface
178 110
        $this->app->singleton(
179 110
            'Laraflock\Dashboard\Repositories\Module\ModuleRepositoryInterface',
180 110
            config('laraflock.dashboard.moduleRepositoryClass')
181 110
        );
182 110
    }
183
184
    /**
185
     * Register the console commands to the application.
186
     *
187
     * Register the following commands:
188
     * - dashboard:install
189
     * - dashboard:fresh
190
     */
191 110
    protected function setupConsoleCommands()
192
    {
193
        // Share dashboard:install command with the application.
194
        $this->app['dashboard::install'] = $this->app->share(function () {
195 110
            return new InstallerCommand();
196 110
        });
197
198
        // Share dashboard:setup command with the application.
199
        $this->app['dashboard::setup'] = $this->app->share(function () {
200 110
            return new SetupCommand();
201 110
        });
202
203
        // Share dashboard:fresh command with the application.
204
        $this->app['dashboard::fresh'] = $this->app->share(function () {
205 110
            return new FreshCommand();
206 110
        });
207
208
        // Share dashboard:uninstall command with the application.
209 110
        $this->app['dashboard::uninstall'] = $this->app->share(function () {
210 110
            return new UninstallCommand();
211 110
        });
212
213
        // Adds dashboard:install to the console kernel.
214 110
        $this->commands('dashboard::install');
215
216
        // Adds dashboard:setup to the console kernel.
217 110
        $this->commands('dashboard::setup');
218
219
        // Adds dashboard:fresh to the console kernel.
220 110
        $this->commands('dashboard::fresh');
221
222
        // Adds dashboard:uninstall to the console kernel.
223 110
        $this->commands('dashboard::uninstall');
224 110
    }
225
226
    /**
227
     * Register the Facades to the application.
228
     *
229
     * Registers the following facades:
230
     * - Activation
231
     * - Reminder
232
     * - Sentinel
233
     * - Flash
234
     * - Ekko
235
     * - Form
236
     * - BootForm
237
     */
238 110
    protected function setupFacades()
239
    {
240
        // Setup alias loader.
241 110
        $loader = AliasLoader::getInstance();
242
243
        // Load Sentinel
244
        // - Activation
245
        // - Reminder
246
        // - Sentinel
247 110
        $loader->alias('Activation', Activation::class);
248 110
        $loader->alias('Reminder', Reminder::class);
249 110
        $loader->alias('Sentinel', Sentinel::class);
250
251
        // Load Flash
252 110
        $loader->alias('Flash', Flash::class);
253
254
        // Load Ekko
255 110
        $loader->alias('Ekko', Ekko::class);
256
257
        // Carbon
258 110
        $loader->alias('Carbon', Carbon::class);
259
260
        // Load Form
261
        // - Form
262
        // - BootForm
263 110
        $loader->alias('Form', Form::class);
264 110
        $loader->alias('BootForm', BootForm::class);
265
    }
266
}