Completed
Pull Request — master (#87)
by Owen
02:01
created

BaseServiceProvider   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 134
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 10
Bugs 5 Features 1
Metric Value
dl 0
loc 134
rs 10
c 10
b 5
f 1
wmc 9
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 49 1
B setupRoutes() 0 30 4
B register() 0 26 4
1
<?php
2
3
namespace Backpack\Base;
4
5
use Config;
6
use Illuminate\Routing\Router;
7
use Illuminate\Support\ServiceProvider;
8
use Route;
9
10
class BaseServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Indicates if loading of the provider is deferred.
14
     *
15
     * @var bool
16
     */
17
    protected $defer = false;
18
19
    /**
20
     * Perform post-registration booting of services.
21
     *
22
     * @return void
23
     */
24
    public function boot(\Illuminate\Routing\Router $router)
25
    {
26
        // -------------
27
        // LOAD THE VIEWS
28
        // -------------
29
        // first the published views (in case they have any changes)
30
        $this->loadViewsFrom(resource_path('views/vendor/backpack/base'), 'backpack');
31
        // then the stock views that come with the package, in case a published view might be missing
32
        $this->loadViewsFrom(realpath(__DIR__.'/resources/views'), 'backpack');
33
34
        $this->loadTranslationsFrom(realpath(__DIR__.'/resources/lang'), 'backpack');
35
36
        // use the vendor configuration file as fallback
37
        $this->mergeConfigFrom(
38
            __DIR__.'/config/backpack/base.php',
39
            'backpack.base'
40
        );
41
42
        // -------------
43
        // AUTH GUARD CONFIGURATION
44
        // -------------
45
        $appAuthGuards = Config::get('auth.guards');
46
        $backpackAuthGuard = Config::get('backpack.base.admin_guard');
47
        $appAuthGuards[$backpackAuthGuard['name']] = $backpackAuthGuard;
48
        Config::set('auth.guards', $appAuthGuards);
49
50
        $this->setupRoutes($this->app->router);
0 ignored issues
show
Bug introduced by
Accessing router on the interface Illuminate\Contracts\Foundation\Application suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
51
52
        // -------------
53
        // PUBLISH FILES
54
        // -------------
55
        // publish config file
56
        $this->publishes([__DIR__.'/config' => config_path()], 'config');
57
        // publish lang files
58
        $this->publishes([__DIR__.'/resources/lang' => resource_path('lang/vendor/backpack')], 'lang');
59
        // publish views
60
        $this->publishes([__DIR__.'/resources/views' => resource_path('views/vendor/backpack/base')], 'views');
61
        // publish error views
62
        $this->publishes([__DIR__.'/resources/error_views' => resource_path('views/errors')], 'errors');
63
        // publish public Backpack assets
64
        $this->publishes([__DIR__.'/public' => public_path('vendor/backpack')], 'public');
65
        // publish public AdminLTE assets
66
        $this->publishes([base_path('vendor/almasaeed2010/adminlte') => public_path('vendor/adminlte')], 'adminlte');
67
68
        // -------------
69
        // HELPERS
70
        // -------------
71
        require_once __DIR__.'/helpers.php';
72
    }
73
74
    /**
75
     * Define the routes for the application.
76
     *
77
     * @param \Illuminate\Routing\Router $router
78
     *
79
     * @return void
80
     */
81
    public function setupRoutes(Router $router)
82
    {
83
        // register the 'admin' middleware
84
        $router->middleware('backpack.base.admin', app\Http\Middleware\BackpackBaseAdmin::class);
85
86
        if (config('backpack.base.separate_admin_session')) {
87
            $router->middleware('backpack.admin.guard', app\Http\Middleware\BackpackAdminGuard::class);
88
        }
89
90
        $router->group(['namespace' => 'Backpack\Base\app\Http\Controllers'], function ($router) {
0 ignored issues
show
Unused Code introduced by
The parameter $router 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...
91
            Route::group(
92
                [
93
                    'middleware' => 'web',
94
                    'prefix'     => config('backpack.base.route_prefix'),
95
                ],
96
                function () {
97
                    // if not otherwise configured, setup the auth routes
98
                    if (config('backpack.base.setup_auth_routes')) {
99
                        Route::auth();
100
                        Route::get('logout', 'Auth\LoginController@logout');
101
                    }
102
103
                    // if not otherwise configured, setup the dashboard routes
104
                    if (config('backpack.base.setup_dashboard_routes')) {
105
                        Route::get('dashboard', 'AdminController@dashboard');
106
                        Route::get('/', 'AdminController@redirect');
107
                    }
108
                });
109
        });
110
    }
111
112
    /**
113
     * Register any package services.
114
     *
115
     * @return void
116
     */
117
    public function register()
118
    {
119
        // register the current package
120
        $this->app->bind('base', function ($app) {
121
            return new Base($app);
122
        });
123
124
        // register its dependencies
125
        $this->app->register(\Jenssegers\Date\DateServiceProvider::class);
126
        $this->app->register(\Prologue\Alerts\AlertsServiceProvider::class);
127
128
        // register their aliases
129
        $loader = \Illuminate\Foundation\AliasLoader::getInstance();
130
        $loader->alias('Alert', \Prologue\Alerts\Facades\Alert::class);
131
        $loader->alias('Date', \Jenssegers\Date\Date::class);
132
133
        // register the services that are only used for development
134
        if ($this->app->environment() == 'local') {
135
            if (class_exists('Laracasts\Generators\GeneratorsServiceProvider')) {
136
                $this->app->register('Laracasts\Generators\GeneratorsServiceProvider');
137
            }
138
            if (class_exists('Backpack\Generators\GeneratorsServiceProvider')) {
139
                $this->app->register('Backpack\Generators\GeneratorsServiceProvider');
140
            }
141
        }
142
    }
143
}
144