1 |
cb15593b
|
Cajova-Houba
|
<?php
|
2 |
|
|
|
3 |
|
|
namespace Illuminate\Auth;
|
4 |
|
|
|
5 |
|
|
use Illuminate\Auth\Access\Gate;
|
6 |
|
|
use Illuminate\Support\ServiceProvider;
|
7 |
|
|
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
|
8 |
|
|
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
9 |
|
|
|
10 |
|
|
class AuthServiceProvider extends ServiceProvider
|
11 |
|
|
{
|
12 |
|
|
/**
|
13 |
|
|
* Register the service provider.
|
14 |
|
|
*
|
15 |
|
|
* @return void
|
16 |
|
|
*/
|
17 |
|
|
public function register()
|
18 |
|
|
{
|
19 |
|
|
$this->registerAuthenticator();
|
20 |
|
|
|
21 |
|
|
$this->registerUserResolver();
|
22 |
|
|
|
23 |
|
|
$this->registerAccessGate();
|
24 |
|
|
|
25 |
|
|
$this->registerRequestRebindHandler();
|
26 |
|
|
}
|
27 |
|
|
|
28 |
|
|
/**
|
29 |
|
|
* Register the authenticator services.
|
30 |
|
|
*
|
31 |
|
|
* @return void
|
32 |
|
|
*/
|
33 |
|
|
protected function registerAuthenticator()
|
34 |
|
|
{
|
35 |
|
|
$this->app->singleton('auth', function ($app) {
|
36 |
|
|
// Once the authentication service has actually been requested by the developer
|
37 |
|
|
// we will set a variable in the application indicating such. This helps us
|
38 |
|
|
// know that we need to set any queued cookies in the after event later.
|
39 |
|
|
$app['auth.loaded'] = true;
|
40 |
|
|
|
41 |
|
|
return new AuthManager($app);
|
42 |
|
|
});
|
43 |
|
|
|
44 |
|
|
$this->app->singleton('auth.driver', function ($app) {
|
45 |
|
|
return $app['auth']->guard();
|
46 |
|
|
});
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
/**
|
50 |
|
|
* Register a resolver for the authenticated user.
|
51 |
|
|
*
|
52 |
|
|
* @return void
|
53 |
|
|
*/
|
54 |
|
|
protected function registerUserResolver()
|
55 |
|
|
{
|
56 |
|
|
$this->app->bind(
|
57 |
|
|
AuthenticatableContract::class, function ($app) {
|
58 |
|
|
return call_user_func($app['auth']->userResolver());
|
59 |
|
|
}
|
60 |
|
|
);
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
/**
|
64 |
|
|
* Register the access gate service.
|
65 |
|
|
*
|
66 |
|
|
* @return void
|
67 |
|
|
*/
|
68 |
|
|
protected function registerAccessGate()
|
69 |
|
|
{
|
70 |
|
|
$this->app->singleton(GateContract::class, function ($app) {
|
71 |
|
|
return new Gate($app, function () use ($app) {
|
72 |
|
|
return call_user_func($app['auth']->userResolver());
|
73 |
|
|
});
|
74 |
|
|
});
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
/**
|
78 |
|
|
* Register a resolver for the authenticated user.
|
79 |
|
|
*
|
80 |
|
|
* @return void
|
81 |
|
|
*/
|
82 |
|
|
protected function registerRequestRebindHandler()
|
83 |
|
|
{
|
84 |
|
|
$this->app->rebinding('request', function ($app, $request) {
|
85 |
|
|
$request->setUserResolver(function ($guard = null) use ($app) {
|
86 |
|
|
return call_user_func($app['auth']->userResolver(), $guard);
|
87 |
|
|
});
|
88 |
|
|
});
|
89 |
|
|
}
|
90 |
|
|
}
|