1
|
|
|
<?php namespace Usman\Guardian; |
2
|
|
|
|
3
|
|
|
use Illuminate\Support\ServiceProvider; |
4
|
|
|
|
5
|
|
|
class GuardianServiceProvider extends ServiceProvider { |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Indicates if loading of the provider is deferred. |
9
|
|
|
* |
10
|
|
|
* @var bool |
11
|
|
|
*/ |
12
|
|
|
protected $defer = false; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Bootstrap the package. |
16
|
|
|
* |
17
|
|
|
* @return void |
18
|
|
|
*/ |
19
|
|
|
public function boot() |
20
|
|
|
{ |
21
|
|
|
$this->loadAndPublishViews(); |
22
|
|
|
$this->publishAssets(); |
23
|
|
|
$this->publishConfig(); |
24
|
|
|
$this->publishMigrations(); |
25
|
|
|
|
26
|
|
|
//routes |
27
|
|
|
include __DIR__.'/Http/routes.php'; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Register the service provider. |
32
|
|
|
* |
33
|
|
|
* @return void |
34
|
|
|
*/ |
35
|
|
|
public function register() |
36
|
|
|
{ |
37
|
|
|
$this->mergeConfiguration(); |
38
|
|
|
|
39
|
|
|
//register other providers |
40
|
|
|
$this->app->register('Usman\Guardian\Repositories\Providers\UserRepositoryServiceProvider'); |
41
|
|
|
$this->app->register('Usman\Guardian\Repositories\Providers\RoleRepositoryServiceProvider'); |
42
|
|
|
$this->app->register('Usman\Guardian\Repositories\Providers\CapabilityRepositoryServiceProvider'); |
43
|
|
|
$this->app->register('Usman\Guardian\AccessControl\GuardianServiceProvider'); |
44
|
|
|
$this->app->register('Usman\Guardian\Composers\ComposersServiceProvider'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* loads and publishes the package view files |
49
|
|
|
* |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
|
|
private function loadAndPublishViews() |
53
|
|
|
{ |
54
|
|
|
$viewPath = __DIR__.'/../../views'; |
55
|
|
|
$this->loadViewsFrom($viewPath, 'guardian'); |
56
|
|
|
|
57
|
|
|
$this->publishes([ |
58
|
|
|
$viewPath => base_path('resources/views/vendor/guardian'), |
59
|
|
|
],'guardian-views'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* publishes the package assets |
64
|
|
|
* |
65
|
|
|
* @return void |
66
|
|
|
*/ |
67
|
|
|
private function publishAssets() |
68
|
|
|
{ |
69
|
|
|
$assetPath = __DIR__.'/../../../public'; |
70
|
|
|
$this->publishes([ |
71
|
|
|
$assetPath => public_path('packages/usm4n/guardian'), |
72
|
|
|
], 'guardian-assets'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* publishes the package config file |
77
|
|
|
* |
78
|
|
|
* @return void |
79
|
|
|
*/ |
80
|
|
|
private function publishConfig() |
81
|
|
|
{ |
82
|
|
|
$configPath = __DIR__.'/../../config/config.php'; |
83
|
|
|
$this->publishes([$configPath => config_path('guardian.php')], 'guardian-config'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* publishes the package migration files |
88
|
|
|
* |
89
|
|
|
* @return void |
90
|
|
|
*/ |
91
|
|
|
private function publishMigrations() |
92
|
|
|
{ |
93
|
|
|
$migrationPath = __DIR__.'/../../migrations'; |
94
|
|
|
$this->publishes([$migrationPath => base_path('database/migrations')], 'guardian-migrations'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* merges the package config with the app config |
99
|
|
|
* |
100
|
|
|
* @return void |
101
|
|
|
*/ |
102
|
|
|
private function mergeConfiguration() |
103
|
|
|
{ |
104
|
|
|
$configPath = __DIR__.'/../../config/config.php'; |
105
|
|
|
$this->mergeConfigFrom($configPath, 'guardian'); |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Get the services provided by the provider. |
111
|
|
|
* |
112
|
|
|
* @return array |
113
|
|
|
*/ |
114
|
|
|
public function provides() |
115
|
|
|
{ |
116
|
|
|
return array(); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
} |
120
|
|
|
|