Passed
Push — master ( 62919d...1f65fa )
by Iman
04:23
created

CRUDBoosterServiceProvider   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 133
rs 10
c 0
b 0
f 0
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A defineValidationRules() 0 7 1
A setAliases() 0 10 1
A defineAuthGuard() 0 4 1
A register() 0 20 1
A boot() 0 35 2
A registerThirdPartyPackages() 0 8 1
A registerUserModule() 0 10 1
A registerCrudBoosterModules() 0 12 1
1
<?php
2
namespace Crocodicstudio\Crudbooster;
3
4
use Crocodicstudio\Crudbooster\CBCoreModule\CbUser;
5
use Crocodicstudio\Crudbooster\CBCoreModule\Facades\CbRouter;
6
use Crocodicstudio\Crudbooster\Modules\ApiGeneratorModule\CbApiGeneratorServiceProvider;
7
use Crocodicstudio\Crudbooster\Modules\AuthModule\CbAuthServiceProvider;
8
use Crocodicstudio\Crudbooster\Modules\EmailTemplates\CbEmailTemplatesServiceProvider;
9
use Crocodicstudio\Crudbooster\Modules\FileManagerModule\CbFileManagerServiceProvider;
10
use Crocodicstudio\Crudbooster\Modules\MenuModule\CbMenuServiceProvider;
11
use Crocodicstudio\Crudbooster\Modules\ModuleGenerator\CbModulesGeneratorServiceProvider;
12
use Crocodicstudio\Crudbooster\Modules\NotificationsModule\CbNotificationsServiceProvider;
13
use Crocodicstudio\Crudbooster\Modules\PrivilegeModule\CbPrivilegesServiceProvider;
14
use Crocodicstudio\Crudbooster\Modules\SettingModule\CbSettingsServiceProvider;
15
use Crocodicstudio\Crudbooster\Modules\StatisticModule\CbStatisticsServiceProvider;
16
use Illuminate\Support\ServiceProvider;
17
use Crocodicstudio\Crudbooster\commands\InstallationCommand;
18
use Illuminate\Foundation\AliasLoader;
19
20
class CRUDBoosterServiceProvider extends ServiceProvider
21
{
22
    /**
23
     * Bootstrap the application services.
24
     *
25
     * @return void
26
     */
27
28
    public function boot()
29
    {
30
        $this->loadViewsFrom(__DIR__.'/views', 'crudbooster');
31
        $this->publishes([__DIR__.'/CBCoreModule/configs/crudbooster.php' => config_path('crudbooster.php')], 'cb_config');
32
        $this->publishes([__DIR__.'/localization' => resource_path('lang')], 'cb_localization');
33
34
        /* Integrate LFM to CRUDBooster */
35
        $this->publishes([
36
            __DIR__.'/laravel-filemanager' => base_path('vendor/unisharp/laravel-filemanager'),
37
        ], 'cb_lfm');
38
39
        $this->publishes([
40
            __DIR__.'/laravel-filemanager/public' => public_path('vendor/laravel-filemanager'),
41
        ], 'cb_lfm');
42
43
        $this->publishes([
44
            __DIR__.'/laravel-filemanager/src/config/lfm.php' => config_path('lfm.php'),
45
        ], 'cb_lfm');
46
47
        $this->publishes([
48
            __DIR__.'/laravel-filemanager/src/views/script.blade.php' => resource_path('views/vendor/laravel-filemanager/script.blade.php'),
49
        ], 'cb_lfm');
50
51
        $this->publishes([
52
            __DIR__.'/CBCoreModule/publieshed_files/readme.txt' => resource_path('views/vendor/crudbooster/type_components/readme.txt'),
53
        ], 'cb_type_components');
54
55
        if (! file_exists(app_path('Http/Controllers/AdminUsersController.php'))) {
56
            $this->publishes([__DIR__.'/CBCoreModule/publieshed_files/AdminUsersController.php' => app_path('Http/Controllers/AdminUsersController.php')], 'cb_user_controller');
57
        }
58
59
60
        $this->defineValidationRules();
61
        $this->loadRoutesFrom( __DIR__.'/routes.php');
62
        $this->registerUserModule();
63
    }
64
65
    /**
66
     * Register the application services.
67
     *
68
     * @return void
69
     */
70
    public function register()
71
    {
72
        $this->mergeConfigFrom(__DIR__.'/CBCoreModule/configs/crudbooster.php', 'crudbooster');
73
74
        $this->app->singleton('crudbooster', function () {
75
            return true;
76
        });
77
78
        $this->commands(InstallationCommand::class);
79
80
        $this->defineAuthGuard();
81
82
        $this->registerThirdPartyPackages();
83
84
        $this->setAliases();
85
86
        $this->app->singleton(\Crocodicstudio\Crudbooster\CBCoreModule\CbRouter::class);
87
        $this->registerCrudBoosterModules();
88
        $this->app->singleton('CbDynamicMenus', \Crocodicstudio\Crudbooster\CBCoreModule\DynamicMenus::class);
89
        $this->app->singleton('CbModulesRegistery', \Crocodicstudio\Crudbooster\CBCoreModule\ModulesRegistery::class);
90
    }
91
92
    private function defineValidationRules()
93
    {
94
        \Validator::extend('alpha_spaces', function ($attribute, $value) {
95
            // This will only accept alpha and spaces.
96
            // If you want to accept hyphens use: /^[\pL\s-]+$/u.
97
            return preg_match('/^[\pL\s]+$/u', $value);
98
        }, 'The :attribute should be letters only');
99
    }
100
101
    private function defineAuthGuard()
102
    {
103
        config()->offsetSet('auth.providers.cb_users', ['driver' => 'eloquent', 'model' => CbUser::class,]);
104
        config()->offsetSet('auth.guards.cbAdmin', ['driver' => 'session', 'provider' => 'cb_users']);
105
    }
106
107
    private function setAliases(): void
108
    {
109
        $loader = AliasLoader::getInstance();
110
        $loader->alias('PDF', 'Barryvdh\DomPDF\Facade');
111
        $loader->alias('Excel', 'Maatwebsite\Excel\Facades\Excel');
112
        $loader->alias('Image', 'Intervention\Image\Facades\Image');
113
        $loader->alias('CRUDBooster', 'Crocodicstudio\Crudbooster\helpers\CRUDBooster');
114
        $loader->alias('CB', 'Crocodicstudio\Crudbooster\helpers\CRUDBooster');
115
        $loader->alias('DbInspector', 'Crocodicstudio\Crudbooster\helpers\DbInspector');
116
        $loader->alias('CbRouter', CbRouter::class);
117
    }
118
119
    private function registerThirdPartyPackages(): void
120
    {
121
        $this->app->register('Barryvdh\DomPDF\ServiceProvider');
122
        $this->app->register('Maatwebsite\Excel\ExcelServiceProvider');
123
        $this->app->register('Unisharp\Laravelfilemanager\LaravelFilemanagerServiceProvider');
124
        $this->app->register('Intervention\Image\ImageServiceProvider');
125
        $this->app->register('Imanghafoori\Widgets\WidgetsServiceProvider');
126
        $this->app->register('Imanghafoori\Responder\LaravelResponderServiceProvider');
127
    }
128
129
    private function registerCrudBoosterModules()
130
    {
131
        $this->app->register(CbAuthServiceProvider::class);
132
        $this->app->register(CbApiGeneratorServiceProvider::class);
133
        $this->app->register(CbModulesGeneratorServiceProvider::class);
134
        $this->app->register(CbSettingsServiceProvider::class);
135
        $this->app->register(CbStatisticsServiceProvider::class);
136
        $this->app->register(CbPrivilegesServiceProvider::class);
137
        $this->app->register(CbMenuServiceProvider::class);
138
        $this->app->register(CbFileManagerServiceProvider::class);
139
        $this->app->register(CbNotificationsServiceProvider::class);
140
        $this->app->register(CbEmailTemplatesServiceProvider::class);
141
    }
142
143
    private function registerUserModule()
144
    {
145
        app('CbModulesRegistery')->addModule('users', (object)[
0 ignored issues
show
Bug introduced by
The method addModule() does not exist on Illuminate\Foundation\Application. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

145
        app('CbModulesRegistery')->/** @scrutinizer ignore-call */ addModule('users', (object)[

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
146
            'name' => trans('crudbooster.Users_Management'),
147
            'icon' => 'fa fa-users',
148
            'path' => 'users',
149
            'table_name' => 'cms_users',
150
            'controller' => 'AdminCmsUsersController',
151
            'is_protected' => 0,
152
            'is_active' => 1,
153
        ]);
154
    }
155
}
156