1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Devpri\Tinre; |
4
|
|
|
|
5
|
|
|
use Devpri\Tinre\Guards\TokenGuard; |
6
|
|
|
use Illuminate\Auth\RequestGuard; |
7
|
|
|
use Illuminate\Support\Facades\Auth; |
8
|
|
|
use Illuminate\Support\Facades\Gate; |
9
|
|
|
use Illuminate\Support\ServiceProvider; |
10
|
|
|
|
11
|
|
|
class TinreServiceProvider extends ServiceProvider |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* The policy mappings for the application. |
15
|
|
|
* |
16
|
|
|
* @var array |
17
|
|
|
*/ |
18
|
|
|
protected $policies = [ |
19
|
|
|
'Devpri\Tinre\Models\User' => 'Devpri\Tinre\Policies\UserPolicy', |
20
|
|
|
'Devpri\Tinre\Models\Url' => 'Devpri\Tinre\Policies\UrlPolicy', |
21
|
|
|
'Devpri\Tinre\Models\AccessToken' => 'Devpri\Tinre\Policies\AccessTokenPolicy', |
22
|
|
|
]; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Perform post-registration booting of services. |
26
|
|
|
* |
27
|
|
|
* @return void |
28
|
|
|
*/ |
29
|
166 |
|
public function boot() |
30
|
|
|
{ |
31
|
166 |
|
$this->registerRoutes(); |
32
|
|
|
|
33
|
166 |
|
$this->registerPolicies(); |
34
|
|
|
|
35
|
166 |
|
$this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'tinre'); |
36
|
|
|
|
37
|
166 |
|
$this->loadJsonTranslationsFrom(resource_path('lang/vendor/tinre')); |
38
|
|
|
|
39
|
166 |
|
$this->loadViewsFrom(__DIR__.'/../resources/views', 'tinre'); |
40
|
|
|
|
41
|
166 |
|
$this->loadMigrationsFrom(__DIR__.'/../database/migrations'); |
42
|
|
|
|
43
|
166 |
|
$this->listenEvents(); |
44
|
|
|
|
45
|
|
|
// Publishing is only necessary when using the CLI. |
46
|
166 |
|
if ($this->app->runningInConsole()) { |
47
|
166 |
|
$this->bootForConsole(); |
48
|
|
|
} |
49
|
166 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Register any package services. |
53
|
|
|
* |
54
|
|
|
* @return void |
55
|
|
|
*/ |
56
|
166 |
|
public function register() |
57
|
|
|
{ |
58
|
166 |
|
$this->mergeConfigFrom(__DIR__.'/../config/tinre.php', 'tinre'); |
59
|
|
|
|
60
|
166 |
|
$this->registerTokenGuard(); |
61
|
|
|
|
62
|
166 |
|
Tinre::addTranslation( |
63
|
166 |
|
resource_path('lang/vendor/tinre/'.app()->getLocale().'.json') |
|
|
|
|
64
|
|
|
); |
65
|
166 |
|
} |
66
|
|
|
|
67
|
166 |
|
protected function registerRoutes() |
68
|
|
|
{ |
69
|
166 |
|
Tinre::routes() |
70
|
166 |
|
->withHomeRoute() |
71
|
166 |
|
->withAuthenticationRoutes() |
72
|
166 |
|
->withRegisterRoutes() |
73
|
166 |
|
->withPasswordResetRoutes() |
74
|
166 |
|
->withVerificationRoutes() |
75
|
166 |
|
->withEmailChangeRoutes(); |
76
|
166 |
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Register the application's policies. |
80
|
|
|
* |
81
|
|
|
* @return void |
82
|
|
|
*/ |
83
|
166 |
|
public function registerPolicies() |
84
|
|
|
{ |
85
|
166 |
|
foreach ($this->policies as $key => $value) { |
86
|
166 |
|
Gate::policy($key, $value); |
87
|
|
|
} |
88
|
166 |
|
} |
89
|
|
|
|
90
|
166 |
|
protected function listenEvents() |
91
|
|
|
{ |
92
|
166 |
|
\Illuminate\Support\Facades\Event::listen( |
93
|
166 |
|
\Devpri\Tinre\Events\EmailChangeCreated::class, |
94
|
166 |
|
\Devpri\Tinre\Listeners\SendEmailChangeNotification::class |
95
|
|
|
); |
96
|
|
|
|
97
|
166 |
|
\Illuminate\Support\Facades\Event::listen( |
98
|
166 |
|
\Devpri\Tinre\Events\UserRegistered::class, |
99
|
166 |
|
\Devpri\Tinre\Listeners\SendEmailVerificationNotification::class |
100
|
|
|
); |
101
|
166 |
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Get the services provided by the provider. |
105
|
|
|
* |
106
|
|
|
* @return array |
107
|
|
|
*/ |
108
|
|
|
public function provides() |
109
|
|
|
{ |
110
|
|
|
return ['tinre']; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Console-specific booting. |
115
|
|
|
* |
116
|
|
|
* @return void |
117
|
|
|
*/ |
118
|
166 |
|
protected function bootForConsole() |
119
|
|
|
{ |
120
|
|
|
// Publishing the configuration file. |
121
|
166 |
|
$this->publishes([ |
122
|
166 |
|
__DIR__.'/../config/tinre.php' => config_path('tinre.php'), |
123
|
166 |
|
], 'tinre-config'); |
124
|
|
|
|
125
|
166 |
|
$this->publishes([ |
126
|
166 |
|
__DIR__.'/../stubs/TinreServiceProvider.stub' => app_path('Providers/TinreServiceProvider.php'), |
127
|
166 |
|
], 'tinre-provider'); |
128
|
|
|
|
129
|
|
|
// Publishing the views. |
130
|
166 |
|
$this->publishes([ |
131
|
166 |
|
__DIR__.'/../resources/views/partials' => base_path('resources/views/vendor/tinre/partials'), |
132
|
166 |
|
], 'tinre-views'); |
133
|
|
|
|
134
|
|
|
// Publishing assets. |
135
|
166 |
|
$this->publishes([ |
136
|
166 |
|
__DIR__.'/../public' => public_path('vendor/tinre'), |
137
|
166 |
|
], 'tinre-assets'); |
138
|
|
|
|
139
|
|
|
// Publishing the translation files. |
140
|
166 |
|
$this->publishes([ |
141
|
166 |
|
__DIR__.'/../resources/lang' => resource_path('lang/vendor/tinre'), |
142
|
166 |
|
], 'tinre-lang'); |
143
|
166 |
|
} |
144
|
|
|
|
145
|
166 |
|
protected function registerTokenGuard() |
146
|
|
|
{ |
147
|
166 |
|
Auth::resolved(function ($auth) { |
148
|
112 |
|
$auth->extend('token', function ($app, $name, array $config) { |
|
|
|
|
149
|
35 |
|
return tap($this->makeTokenGuard(), function ($guard) { |
150
|
35 |
|
$this->app->refresh('request', $guard, 'setRequest'); |
151
|
35 |
|
}); |
152
|
112 |
|
}); |
153
|
166 |
|
}); |
154
|
166 |
|
} |
155
|
|
|
|
156
|
35 |
|
protected function makeTokenGuard() |
157
|
|
|
{ |
158
|
35 |
|
return new RequestGuard(function ($request) { |
159
|
3 |
|
return (new TokenGuard( |
160
|
3 |
|
$request |
161
|
3 |
|
))->user(); |
162
|
35 |
|
}, $this->app['request']); |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|