1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AuthService; |
4
|
|
|
|
5
|
|
|
use AuthService\Contracts\AuthServiceConfigInterface; |
6
|
|
|
use InvalidArgumentException; |
7
|
|
|
|
8
|
|
|
class AuthServiceConfig implements AuthServiceConfigInterface |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Authentication event listener class. |
12
|
|
|
* |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $authEventListenerClass; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Login failed message. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $loginFailedMessage; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* After login success path. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $afterLoginSuccessPath; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* After logout success path. |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $afterLogoutSuccessPath; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Create a new instance of AuthServiceConfig class. |
40
|
|
|
* |
41
|
|
|
* @param string $authEventListenerClass |
42
|
|
|
* @param string $loginFailedMessage |
43
|
|
|
* @param string $afterLoginSuccessPath |
44
|
|
|
* @param string $afterLogoutSuccessPath |
45
|
|
|
*/ |
46
|
9 |
|
public function __construct($authEventListenerClass, $loginFailedMessage, $afterLoginSuccessPath, $afterLogoutSuccessPath) |
47
|
|
|
{ |
48
|
9 |
|
$this->authEventListenerClass = $authEventListenerClass; |
49
|
9 |
|
$this->loginFailedMessage = $loginFailedMessage; |
50
|
9 |
|
$this->afterLoginSuccessPath = $afterLoginSuccessPath; |
51
|
9 |
|
$this->afterLogoutSuccessPath = $afterLogoutSuccessPath; |
52
|
9 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get authentication event listener class. |
56
|
|
|
* |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
2 |
|
public function authEventListenerClass() |
60
|
|
|
{ |
61
|
2 |
|
return $this->authEventListenerClass; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get login failed message. |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
2 |
|
public function loginFailedMessage() |
70
|
|
|
{ |
71
|
2 |
|
return $this->loginFailedMessage; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get after login success path. |
76
|
|
|
* |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
2 |
|
public function afterLoginSuccessPath() |
80
|
|
|
{ |
81
|
2 |
|
return $this->afterLoginSuccessPath; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get after logout success path. |
86
|
|
|
* |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
2 |
|
public function afterLogoutSuccessPath() |
90
|
|
|
{ |
91
|
2 |
|
return $this->afterLogoutSuccessPath; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Create an instance of AuthServiceConfig from array. |
96
|
|
|
* |
97
|
|
|
* @param array $config |
98
|
|
|
* |
99
|
|
|
* @return \AuthService\Contracts\AuthServiceConfigInterface |
100
|
|
|
*/ |
101
|
5 |
|
public static function fromArray(array $config) |
102
|
|
|
{ |
103
|
|
|
$requiredParams = [ |
104
|
5 |
|
'auth_event_listener_class', |
105
|
5 |
|
'login_failed_message', |
106
|
5 |
|
'after_login_success_path', |
107
|
5 |
|
'after_logout_success_path', |
108
|
5 |
|
]; |
109
|
|
|
|
110
|
5 |
|
foreach ($requiredParams as $param) { |
111
|
5 |
|
if (! isset($config[$param])) { |
112
|
4 |
|
throw new InvalidArgumentException("Missing auth service configuration: $param."); |
113
|
|
|
} |
114
|
4 |
|
} |
115
|
|
|
|
116
|
1 |
|
return new static( |
117
|
1 |
|
$config['auth_event_listener_class'], |
118
|
1 |
|
$config['login_failed_message'], |
119
|
1 |
|
$config['after_login_success_path'], |
120
|
1 |
|
$config['after_logout_success_path'] |
121
|
1 |
|
); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|