20
20
use ActiveCollab \Authentication \Authorizer \AuthorizerInterface ;
21
21
use ActiveCollab \Authentication \Exception \InvalidAuthenticationRequestException ;
22
22
use Exception ;
23
- use InvalidArgumentException ;
24
- use LogicException ;
25
23
use Psr \Http \Message \ResponseInterface ;
26
24
use Psr \Http \Message \ServerRequestInterface ;
27
25
use Psr \Http \Server \RequestHandlerInterface ;
28
26
29
27
class Authentication implements AuthenticationInterface
30
28
{
31
- /**
32
- * @var AdapterInterface[]
33
- */
34
- private $ adapters ;
35
-
36
- /**
37
- * Authenticated user instance.
38
- *
39
- * @var AuthenticatedUserInterface|null
40
- */
41
- private $ authenticated_user ;
42
-
43
- /**
44
- * @var AuthenticationResultInterface|null
45
- */
46
- private $ authenticated_with ;
47
-
48
- /**
49
- * @var callable[]
50
- */
51
- private $ on_user_authenticated = [];
52
-
53
- /**
54
- * @var callable[]
55
- */
56
- private $ on_user_authorized = [];
57
-
58
- /**
59
- * @var callable[]
60
- */
61
- private $ on_user_authorization_failed = [];
62
-
63
- /**
64
- * @var callable[]
65
- */
66
- private $ on_user_set = [];
67
-
68
- /**
69
- * @var callable[]
70
- */
71
- private $ on_user_deauthenticated = [];
29
+ private array $ adapters ;
30
+ private ?AuthenticatedUserInterface $ authenticated_user = null ;
31
+ private ?AuthenticationResultInterface $ authenticated_with = null ;
32
+ private array $ on_user_authenticated = [];
33
+ private array $ on_user_authorized = [];
34
+ private array $ on_user_authorization_failed = [];
35
+ private array $ on_user_set = [];
36
+ private array $ on_user_deauthenticated = [];
72
37
73
38
public function __construct (AdapterInterface ...$ adapters )
74
39
{
75
- foreach ($ adapters as $ adapter ) {
76
- if (!($ adapter instanceof AdapterInterface)) {
77
- throw new LogicException ('Invalid authentication adapter provided ' );
78
- }
79
- }
80
-
81
40
$ this ->adapters = $ adapters ;
82
41
}
83
42
@@ -114,7 +73,7 @@ public function __invoke(
114
73
return $ response ;
115
74
}
116
75
117
- public $ lastProcessingResult ;
76
+ public ? TransportInterface $ lastProcessingResult = null ;
118
77
119
78
public function process (
120
79
ServerRequestInterface $ request ,
@@ -204,7 +163,6 @@ private function authenticatedUsingAdapters(ServerRequestInterface $request): ?T
204
163
$ last_exception = null ;
205
164
$ results = [];
206
165
207
- /** @var AdapterInterface $adapter */
208
166
foreach ($ this ->adapters as $ adapter ) {
209
167
try {
210
168
$ initialization_result = $ adapter ->initialize ($ request );
@@ -237,7 +195,7 @@ public function getAuthenticatedUser(): ?AuthenticatedUserInterface
237
195
return $ this ->authenticated_user ;
238
196
}
239
197
240
- public function setAuthenticatedUser (AuthenticatedUserInterface $ user = null ): AuthenticationInterface
198
+ public function setAuthenticatedUser (? AuthenticatedUserInterface $ user ): AuthenticationInterface
241
199
{
242
200
$ this ->authenticated_user = $ user ;
243
201
@@ -258,16 +216,14 @@ public function setAuthenticatedWith(?AuthenticationResultInterface $value): Aut
258
216
return $ this ;
259
217
}
260
218
261
- private function triggerEvent (string $ event_name , ...$ arguments ): AuthenticationInterface
219
+ private function triggerEvent (string $ event_name , ...$ arguments ): void
262
220
{
263
- $ property_name = "on_ { $ event_name}" ;
221
+ $ property_name = sprintf ( "on_%s " , $ event_name) ;
264
222
265
223
/** @var callable $handler */
266
224
foreach ($ this ->$ property_name as $ handler ) {
267
225
call_user_func_array ($ handler , $ arguments );
268
226
}
269
-
270
- return $ this ;
271
227
}
272
228
273
229
public function onUserAuthenticated (callable $ value ): AuthenticationInterface
@@ -304,18 +260,4 @@ public function onUserDeauthenticated(callable $value): AuthenticationInterface
304
260
305
261
return $ this ;
306
262
}
307
-
308
- /**
309
- * Kept for backward compatibility reasons. Will be removed.
310
- *
311
- * {@inheritdoc}
312
- */
313
- public function setOnAuthenciatedUserChanged (callable $ value = null ): AuthenticationInterface
314
- {
315
- if (empty ($ value )) {
316
- throw new InvalidArgumentException ('Value needs to be a callable. ' );
317
- }
318
-
319
- return $ this ->onUserSet ($ value );
320
- }
321
263
}
0 commit comments