Completed
Push — master ( 51af1b...946e33 )
by ARCANEDEV
07:53
created

LaravelAuthServiceProvider::bindModels()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 16
ccs 11
cts 11
cp 1
rs 9.4286
cc 2
eloc 9
nc 2
nop 0
crap 2
1
<?php namespace Arcanedev\LaravelAuth;
2
3
use Arcanedev\Support\PackageServiceProvider as ServiceProvider;
4
use Arcanesoft\Contracts\Auth\Models as AuthContracts;
5
6
/**
7
 * Class     LaravelAuthServiceProvider
8
 *
9
 * @package  Arcanedev\LaravelAuth
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class LaravelAuthServiceProvider extends ServiceProvider
13
{
14
    /* ------------------------------------------------------------------------------------------------
15
     |  Properties
16
     | ------------------------------------------------------------------------------------------------
17
     */
18
    /**
19
     * Vendor name.
20
     *
21
     * @var string
22
     */
23
    protected $vendor  = 'arcanedev';
24
25
    /**
26
     * Package name.
27
     *
28
     * @var string
29
     */
30
    protected $package = 'laravel-auth';
31
32
    /* ------------------------------------------------------------------------------------------------
33
     |  Getters & Setters
34
     | ------------------------------------------------------------------------------------------------
35
     */
36
    /**
37
     * Get the base path of the package.
38
     *
39
     * @return string
40
     */
41 528
    public function getBasePath()
42
    {
43 528
        return dirname(__DIR__);
44
    }
45
46
    /* ------------------------------------------------------------------------------------------------
47
     |  Main Functions
48
     | ------------------------------------------------------------------------------------------------
49
     */
50
    /**
51
     * Register the service provider.
52
     */
53 528
    public function register()
54
    {
55 528
        $this->registerConfig();
56
57 528
        $this->bindModels();
58
59 528
        if ($this->app['config']->get('laravel-auth.use-observers', false)) {
60 528
            $this->app->register(Providers\EventServiceProvider::class);
61 396
        }
62 528
    }
63
64
    /**
65
     * Boot the service provider.
66
     */
67 528
    public function boot()
68
    {
69 528
        parent::boot();
70
71 528
        $this->registerPublishes();
72 528
    }
73
74
    /**
75
     * Get the services provided by the provider.
76
     *
77
     * @return array
78
     */
79 8
    public function provides()
80
    {
81
        return [
82
            //
83 8
        ];
84
    }
85
86
    /* ------------------------------------------------------------------------------------------------
87
     |  Other Functions
88
     | ------------------------------------------------------------------------------------------------
89
     */
90
    /**
91
     * Binding the models with the contracts.
92
     */
93 528
    private function bindModels()
94
    {
95
        /** @var \Illuminate\Contracts\Config\Repository $config */
96 528
        $config = $this->app['config'];
97
98
        $bindings = [
99 528
            'users'              => AuthContracts\User::class,
100 396
            'roles'              => AuthContracts\Role::class,
101 396
            'permissions'        => AuthContracts\Permission::class,
102 396
            'permissions-groups' => AuthContracts\PermissionsGroup::class,
103 396
        ];
104
105 528
        foreach ($bindings as $key => $contract) {
106 528
            $this->bind($contract, $config->get("laravel-auth.$key.model"));
107 396
        }
108 528
    }
109
110
    /**
111
     * Register all publishable stuff.
112
     */
113 528
    private function registerPublishes()
114
    {
115 528
        $this->publishes([
116 528
            $this->getConfigFile() => config_path("{$this->package}.php"),
117 528
        ], 'config');
118
119 528
        $this->publishes([
120 528
            $this->getBasePath() . DS . 'database/migrations' => database_path('migrations'),
121 528
        ], 'migrations');
122
123 528
        $this->publishes([
124 528
            $this->getBasePath() . DS . 'database/factories' => database_path('factories'),
125 528
        ], 'factories');
126 528
    }
127
}
128