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\Passwords;
4
 
5
use Illuminate\Contracts\Auth\PasswordBrokerFactory as FactoryContract;
6
use InvalidArgumentException;
7
 
8
/**
9
 * @mixin \Illuminate\Contracts\Auth\PasswordBroker
10
 */
11
class PasswordBrokerManager implements FactoryContract
12
{
13
    /**
14
     * The application instance.
15
     *
16
     * @var \Illuminate\Contracts\Foundation\Application
17
     */
18
    protected $app;
19
 
20
    /**
21
     * The array of created "drivers".
22
     *
23
     * @var array
24
     */
25
    protected $brokers = [];
26
 
27
    /**
28
     * Create a new PasswordBroker manager instance.
29
     *
30
     * @param  \Illuminate\Contracts\Foundation\Application  $app
31
     * @return void
32
     */
33
    public function __construct($app)
34
    {
35
        $this->app = $app;
36
    }
37
 
38
    /**
39
     * Attempt to get the broker from the local cache.
40
     *
41
     * @param  string|null  $name
42
     * @return \Illuminate\Contracts\Auth\PasswordBroker
43
     */
44
    public function broker($name = null)
45
    {
46
        $name = $name ?: $this->getDefaultDriver();
47
 
48
        return $this->brokers[$name] ?? ($this->brokers[$name] = $this->resolve($name));
49
    }
50
 
51
    /**
52
     * Resolve the given broker.
53
     *
54
     * @param  string  $name
55
     * @return \Illuminate\Contracts\Auth\PasswordBroker
56
     *
57
     * @throws \InvalidArgumentException
58
     */
59
    protected function resolve($name)
60
    {
61
        $config = $this->getConfig($name);
62
 
63
        if (is_null($config)) {
64
            throw new InvalidArgumentException("Password resetter [{$name}] is not defined.");
65
        }
66
 
67
        // The password broker uses a token repository to validate tokens and send user
68
        // password e-mails, as well as validating that password reset process as an
69
        // aggregate service of sorts providing a convenient interface for resets.
70
        return new PasswordBroker(
71
            $this->createTokenRepository($config),
72
            $this->app['auth']->createUserProvider($config['provider'] ?? null)
73
        );
74
    }
75
 
76
    /**
77
     * Create a token repository instance based on the given configuration.
78
     *
79
     * @param  array  $config
80
     * @return \Illuminate\Auth\Passwords\TokenRepositoryInterface
81
     */
82
    protected function createTokenRepository(array $config)
83
    {
84
        $key = $this->app['config']['app.key'];
85
 
86
        if (str_starts_with($key, 'base64:')) {
87
            $key = base64_decode(substr($key, 7));
88
        }
89
 
90
        $connection = $config['connection'] ?? null;
91
 
92
        return new DatabaseTokenRepository(
93
            $this->app['db']->connection($connection),
94
            $this->app['hash'],
95
            $config['table'],
96
            $key,
97
            $config['expire'],
98
            $config['throttle'] ?? 0
99
        );
100
    }
101
 
102
    /**
103
     * Get the password broker configuration.
104
     *
105
     * @param  string  $name
106
     * @return array
107
     */
108
    protected function getConfig($name)
109
    {
110
        return $this->app['config']["auth.passwords.{$name}"];
111
    }
112
 
113
    /**
114
     * Get the default password broker name.
115
     *
116
     * @return string
117
     */
118
    public function getDefaultDriver()
119
    {
120
        return $this->app['config']['auth.defaults.passwords'];
121
    }
122
 
123
    /**
124
     * Set the default password broker name.
125
     *
126
     * @param  string  $name
127
     * @return void
128
     */
129
    public function setDefaultDriver($name)
130
    {
131
        $this->app['config']['auth.defaults.passwords'] = $name;
132
    }
133
 
134
    /**
135
     * Dynamically call the default driver instance.
136
     *
137
     * @param  string  $method
138
     * @param  array  $parameters
139
     * @return mixed
140
     */
141
    public function __call($method, $parameters)
142
    {
143
        return $this->broker()->{$method}(...$parameters);
144
    }
145
}