1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Rinvex\Auth\Services; |
6
|
|
|
|
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
use Illuminate\Contracts\Auth\PasswordBrokerFactory; |
9
|
|
|
use Rinvex\Auth\Contracts\PasswordResetBrokerContract; |
10
|
|
|
|
11
|
|
|
class PasswordResetBrokerManager implements PasswordBrokerFactory |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* The application instance. |
15
|
|
|
* |
16
|
|
|
* @var \Illuminate\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 PasswordResetBroker manager instance. |
29
|
|
|
* |
30
|
|
|
* @param \Illuminate\Foundation\Application $app |
31
|
|
|
*/ |
32
|
|
|
public function __construct($app) |
33
|
|
|
{ |
34
|
|
|
$this->app = $app; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Attempt to get the broker from the local cache. |
39
|
|
|
* |
40
|
|
|
* @param string $name |
|
|
|
|
41
|
|
|
* |
42
|
|
|
* @return \Rinvex\Auth\Contracts\PasswordResetBrokerContract |
43
|
|
|
*/ |
44
|
|
|
public function broker($name = null): PasswordResetBrokerContract |
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
|
|
|
* |
56
|
|
|
* @throws \InvalidArgumentException |
57
|
|
|
* |
58
|
|
|
* @return \Rinvex\Auth\Contracts\PasswordResetBrokerContract |
59
|
|
|
*/ |
60
|
|
|
protected function resolve($name): PasswordResetBrokerContract |
61
|
|
|
{ |
62
|
|
|
$config = $this->getConfig($name); |
63
|
|
|
|
64
|
|
|
if (is_null($config)) { |
65
|
|
|
throw new InvalidArgumentException("Password resetter [{$name}] is not defined."); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return new PasswordResetBroker( |
69
|
|
|
$this->app['auth']->createUserProvider($config['provider']), |
70
|
|
|
$this->app['config']['app.key'], |
71
|
|
|
$config['expire'] |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Get the password reset broker configuration. |
77
|
|
|
* |
78
|
|
|
* @param string $name |
79
|
|
|
* |
80
|
|
|
* @return array |
81
|
|
|
*/ |
82
|
|
|
protected function getConfig($name): array |
83
|
|
|
{ |
84
|
|
|
return $this->app['config']["auth.passwords.{$name}"]; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Get the default password reset broker name. |
89
|
|
|
* |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
public function getDefaultDriver(): string |
93
|
|
|
{ |
94
|
|
|
return $this->app['config']['auth.defaults.passwords']; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Set the default password reset broker name. |
99
|
|
|
* |
100
|
|
|
* @param string $name |
101
|
|
|
* |
102
|
|
|
* @return void |
103
|
|
|
*/ |
104
|
|
|
public function setDefaultDriver($name): void |
105
|
|
|
{ |
106
|
|
|
$this->app['config']['auth.defaults.passwords'] = $name; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Dynamically call the default driver instance. |
111
|
|
|
* |
112
|
|
|
* @param string $method |
113
|
|
|
* @param array $parameters |
114
|
|
|
* |
115
|
|
|
* @return mixed |
116
|
|
|
*/ |
117
|
|
|
public function __call($method, $parameters) |
118
|
|
|
{ |
119
|
|
|
return $this->broker()->{$method}(...$parameters); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.