Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Auth;
4
 
5
use Illuminate\Auth\Access\Gate;
6
use Illuminate\Auth\Middleware\RequirePassword;
7
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
8
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
9
use Illuminate\Contracts\Routing\ResponseFactory;
10
use Illuminate\Contracts\Routing\UrlGenerator;
11
use Illuminate\Support\ServiceProvider;
12
 
13
class AuthServiceProvider extends ServiceProvider
14
{
15
    /**
16
     * Register the service provider.
17
     *
18
     * @return void
19
     */
20
    public function register()
21
    {
22
        $this->registerAuthenticator();
23
        $this->registerUserResolver();
24
        $this->registerAccessGate();
25
        $this->registerRequirePassword();
26
        $this->registerRequestRebindHandler();
27
        $this->registerEventRebindHandler();
28
    }
29
 
30
    /**
31
     * Register the authenticator services.
32
     *
33
     * @return void
34
     */
35
    protected function registerAuthenticator()
36
    {
37
        $this->app->singleton('auth', fn ($app) => new AuthManager($app));
38
 
39
        $this->app->singleton('auth.driver', fn ($app) => $app['auth']->guard());
40
    }
41
 
42
    /**
43
     * Register a resolver for the authenticated user.
44
     *
45
     * @return void
46
     */
47
    protected function registerUserResolver()
48
    {
49
        $this->app->bind(AuthenticatableContract::class, fn ($app) => call_user_func($app['auth']->userResolver()));
50
    }
51
 
52
    /**
53
     * Register the access gate service.
54
     *
55
     * @return void
56
     */
57
    protected function registerAccessGate()
58
    {
59
        $this->app->singleton(GateContract::class, function ($app) {
60
            return new Gate($app, fn () => call_user_func($app['auth']->userResolver()));
61
        });
62
    }
63
 
64
    /**
65
     * Register a resolver for the authenticated user.
66
     *
67
     * @return void
68
     */
69
    protected function registerRequirePassword()
70
    {
71
        $this->app->bind(RequirePassword::class, function ($app) {
72
            return new RequirePassword(
73
                $app[ResponseFactory::class],
74
                $app[UrlGenerator::class],
75
                $app['config']->get('auth.password_timeout')
76
            );
77
        });
78
    }
79
 
80
    /**
81
     * Handle the re-binding of the request binding.
82
     *
83
     * @return void
84
     */
85
    protected function registerRequestRebindHandler()
86
    {
87
        $this->app->rebinding('request', function ($app, $request) {
88
            $request->setUserResolver(function ($guard = null) use ($app) {
89
                return call_user_func($app['auth']->userResolver(), $guard);
90
            });
91
        });
92
    }
93
 
94
    /**
95
     * Handle the re-binding of the event dispatcher binding.
96
     *
97
     * @return void
98
     */
99
    protected function registerEventRebindHandler()
100
    {
101
        $this->app->rebinding('events', function ($app, $dispatcher) {
102
            if (! $app->resolved('auth') ||
103
                $app['auth']->hasResolvedGuards() === false) {
104
                return;
105
            }
106
 
107
            if (method_exists($guard = $app['auth']->guard(), 'setDispatcher')) {
108
                $guard->setDispatcher($dispatcher);
109
            }
110
        });
111
    }
112
}