Completed
Push — master ( 6cd5b8...dc6c0b )
by Mahmoud
03:15
created

MainServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
lcom 2
cbo 5
dl 0
loc 73
rs 10
c 3
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 11 1
A register() 0 7 1
A extendValidationRules() 0 5 1
1
<?php
2
3
namespace App\Port\Provider;
4
5
use App\Port\Broadcast\Providers\MainBroadcastServiceProvider;
6
use App\Port\Foundation\Portals\PortButler;
7
use App\Port\Foundation\Providers\FoundationServiceProvider;
8
use App\Port\Foundation\Traits\FractalTrait;
9
use App\Port\Foundation\Traits\QueryDebuggerTrait;
10
use App\Port\Loader\AutoLoaderTrait;
11
use App\Port\Loader\Helpers\LoaderHelper;
12
use App\Port\Loader\Loaders\FactoriesLoaderTrait;
13
use App\Port\Policy\Providers\MainAuthServiceProvider;
14
use App\Port\Provider\Abstracts\ServiceProviderAbstract;
15
use App\Port\Route\Providers\MainRoutesServiceProvider;
16
use Barryvdh\Cors\ServiceProvider as CorsServiceProvider;
17
use Dingo\Api\Provider\LaravelServiceProvider as DingoApiServiceProvider;
18
use Illuminate\Support\Facades\Schema;
19
use Prettus\Repository\Providers\RepositoryServiceProvider;
20
use Vinkla\Hashids\Facades\Hashids;
21
use Vinkla\Hashids\HashidsServiceProvider;
22
23
/**
24
 * The main Service Provider where all Service Providers gets registered
25
 * this is the only Service Provider that gets injected in the Config/app.php.
26
 *
27
 * A.K.A app/Providers/AppServiceProvider.php
28
 *
29
 * Class MainServiceProvider
30
 *
31
 * @author  Mahmoud Zalt <[email protected]>
32
 */
33
class MainServiceProvider extends ServiceProviderAbstract
34
{
35
36
    use FractalTrait;
37
    use FactoriesLoaderTrait;
38
    use AutoLoaderTrait;
39
40
    /**
41
     * Register any Service Providers on the Port layer (including third party packages).
42
     *
43
     * @var array
44
     */
45
    public $serviceProviders = [
46
        FoundationServiceProvider::class,
47
        DingoApiServiceProvider::class,
48
        CorsServiceProvider::class,
49
        RepositoryServiceProvider::class,
50
        MainRoutesServiceProvider::class,
51
        MainAuthServiceProvider::class,
52
        MainBroadcastServiceProvider::class,
53
        HashidsServiceProvider::class,
54
    ];
55
56
    /**
57
     * Register any Alias on the Port layer (including third party packages).
58
     *
59
     * @var  array
60
     */
61
    protected $aliases = [
62
        'Hashids' => Hashids::class,
63
    ];
64
65
    /**
66
     * Bootstrap any application services.
67
     *
68
     * @return void
69
     */
70
    public function boot()
71
    {
72
        $this->bootLoaders();
73
74
        $this->overrideDefaultFractalSerializer();
75
76
        // solves the "specified key was too long" error, introduced in L5.4
77
        Schema::defaultStringLength(191);
78
79
        $this->extendValidationRules();
80
    }
81
82
    /**
83
     * Register any application services.
84
     *
85
     * @return void
86
     */
87
    public function register()
88
    {
89
        $this->app->alias(LoaderHelper::class, 'LoaderHelper');
90
        $this->app->alias(PortButler::class, 'PortButler');
91
92
        $this->registerLoaders();
93
    }
94
95
    /**
96
     * TODO: to be removed from this class and placed in a trait
97
     *
98
     * Extend the default Laravel validation rules.
99
     */
100
    private function extendValidationRules(){
101
        \Validator::extend('no_spaces', function($attr, $value){
102
            return preg_match('/^\S*$/u', $value);
103
        }, ['String should not contain space.']);
104
    }
105
}
106