|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Rinvex\Auth\Services; |
|
6
|
|
|
|
|
7
|
|
|
use InvalidArgumentException; |
|
8
|
|
|
use Rinvex\Auth\Contracts\EmailVerificationBrokerContract; |
|
9
|
|
|
use Rinvex\Auth\Contracts\EmailVerificationBrokerFactoryContract; |
|
10
|
|
|
|
|
11
|
|
|
class EmailVerificationBrokerManager implements EmailVerificationBrokerFactoryContract |
|
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 EmailVerificationBroker 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\EmailVerificationBrokerContract |
|
43
|
|
|
*/ |
|
44
|
|
|
public function broker($name = null): EmailVerificationBrokerContract |
|
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\EmailVerificationBrokerContract |
|
59
|
|
|
*/ |
|
60
|
|
|
protected function resolve($name): EmailVerificationBrokerContract |
|
61
|
|
|
{ |
|
62
|
|
|
$config = $this->getConfig($name); |
|
63
|
|
|
|
|
64
|
|
|
if (is_null($config)) { |
|
65
|
|
|
throw new InvalidArgumentException("Email verification broker [{$name}] is not defined."); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return new EmailVerificationBroker( |
|
69
|
|
|
$this->app['auth']->createUserProvider($config['provider']), |
|
70
|
|
|
$this->app['config']['app.key'], |
|
71
|
|
|
$config['expire'] |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Get the email verification broker configuration. |
|
77
|
|
|
* |
|
78
|
|
|
* @param string $name |
|
79
|
|
|
* |
|
80
|
|
|
* @return array |
|
81
|
|
|
*/ |
|
82
|
|
|
protected function getConfig($name): array |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->app['config']["rinvex.auth.emailverification.{$name}"]; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Get the default email verification broker name. |
|
89
|
|
|
* |
|
90
|
|
|
* @return string |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getDefaultDriver(): string |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->app['config']['rinvex.auth.emailverification.broker']; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Set the default email verification broker name. |
|
99
|
|
|
* |
|
100
|
|
|
* @param string $name |
|
101
|
|
|
* |
|
102
|
|
|
* @return void |
|
103
|
|
|
*/ |
|
104
|
|
|
public function setDefaultDriver($name): void |
|
105
|
|
|
{ |
|
106
|
|
|
$this->app['config']['rinvex.auth.emailverification.broker'] = $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
@paramannotations 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.