6
6
* (c) A51 doo <[email protected] >. All rights reserved.
7
7
*/
8
8
9
+ declare (strict_types=1 );
10
+
9
11
namespace ActiveCollab \Authentication ;
10
12
11
13
use ActiveCollab \Authentication \Adapter \AdapterInterface ;
24
26
use Psr \Http \Message \ServerRequestInterface ;
25
27
use Psr \Http \Server \RequestHandlerInterface ;
26
28
27
- /**
28
- * @package ActiveCollab\Authentication
29
- */
30
29
class Authentication implements AuthenticationInterface
31
30
{
32
31
/**
33
- * @var array
32
+ * @var AdapterInterface[]
34
33
*/
35
34
private $ adapters ;
36
35
37
36
/**
38
37
* Authenticated user instance.
39
38
*
40
- * @var AuthenticatedUserInterface
39
+ * @var AuthenticatedUserInterface|null
41
40
*/
42
41
private $ authenticated_user ;
43
42
44
43
/**
45
- * @var AuthenticationResultInterface
44
+ * @var AuthenticationResultInterface|null
46
45
*/
47
46
private $ authenticated_with ;
48
47
@@ -71,9 +70,6 @@ class Authentication implements AuthenticationInterface
71
70
*/
72
71
private $ on_user_deauthenticated = [];
73
72
74
- /**
75
- * @param array $adapters
76
- */
77
73
public function __construct (array $ adapters )
78
74
{
79
75
foreach ($ adapters as $ adapter ) {
@@ -118,7 +114,10 @@ public function __invoke(
118
114
return $ response ;
119
115
}
120
116
121
- public function process (ServerRequestInterface $ request , RequestHandlerInterface $ handler ): ResponseInterface
117
+ public function process (
118
+ ServerRequestInterface $ request ,
119
+ RequestHandlerInterface $ handler
120
+ ): ResponseInterface
122
121
{
123
122
$ auth_result = $ this ->authenticatedUsingAdapters ($ request );
124
123
@@ -150,10 +149,12 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
150
149
return $ response ;
151
150
}
152
151
153
- /**
154
- * {@inheritdoc}
155
- */
156
- public function authorize (AuthorizerInterface $ authorizer , AdapterInterface $ adapter , array $ credentials , $ payload = null )
152
+ public function authorize (
153
+ AuthorizerInterface $ authorizer ,
154
+ AdapterInterface $ adapter ,
155
+ array $ credentials ,
156
+ $ payload = null
157
+ ): TransportInterface
157
158
{
158
159
try {
159
160
$ user = $ authorizer ->verifyCredentials ($ credentials );
@@ -169,10 +170,10 @@ public function authorize(AuthorizerInterface $authorizer, AdapterInterface $ada
169
170
}
170
171
}
171
172
172
- /**
173
- * {@inheritdoc}
174
- */
175
- public function terminate ( AdapterInterface $ adapter , AuthenticationResultInterface $ authenticated_with )
173
+ public function terminate (
174
+ AdapterInterface $ adapter ,
175
+ AuthenticationResultInterface $ authenticated_with
176
+ ): TransportInterface
176
177
{
177
178
$ termination_result = $ adapter ->terminate ($ authenticated_with );
178
179
@@ -184,17 +185,12 @@ public function terminate(AdapterInterface $adapter, AuthenticationResultInterfa
184
185
/**
185
186
* {@inheritdoc}
186
187
*/
187
- public function getAdapters ()
188
+ public function getAdapters (): iterable
188
189
{
189
190
return $ this ->adapters ;
190
191
}
191
192
192
- /**
193
- * @param ServerRequestInterface $request
194
- * @return TransportInterface|null
195
- * @throws Exception
196
- */
197
- private function authenticatedUsingAdapters (ServerRequestInterface $ request )
193
+ private function authenticatedUsingAdapters (ServerRequestInterface $ request ): ?TransportInterface
198
194
{
199
195
$ last_exception = null ;
200
196
$ results = [];
@@ -227,18 +223,12 @@ private function authenticatedUsingAdapters(ServerRequestInterface $request)
227
223
return $ results [0 ];
228
224
}
229
225
230
- /**
231
- * {@inheritdoc}
232
- */
233
- public function getAuthenticatedUser ()
226
+ public function getAuthenticatedUser (): ?AuthenticatedUserInterface
234
227
{
235
228
return $ this ->authenticated_user ;
236
229
}
237
230
238
- /**
239
- * {@inheritdoc}
240
- */
241
- public function setAuthenticatedUser (AuthenticatedUserInterface $ user = null )
231
+ public function setAuthenticatedUser (AuthenticatedUserInterface $ user = null ): AuthenticationInterface
242
232
{
243
233
$ this ->authenticated_user = $ user ;
244
234
@@ -247,32 +237,19 @@ public function setAuthenticatedUser(AuthenticatedUserInterface $user = null)
247
237
return $ this ;
248
238
}
249
239
250
- /**
251
- * @return AuthenticationResultInterface|null
252
- */
253
- public function getAuthenticatedWith ()
240
+ public function getAuthenticatedWith (): ?AuthenticationResultInterface
254
241
{
255
242
return $ this ->authenticated_with ;
256
243
}
257
244
258
- /**
259
- * {@inheritdoc}
260
- */
261
- public function setAuthenticatedWith (AuthenticationResultInterface $ value )
245
+ public function setAuthenticatedWith (AuthenticationResultInterface $ value ): AuthenticationInterface
262
246
{
263
247
$ this ->authenticated_with = $ value ;
264
248
265
249
return $ this ;
266
250
}
267
251
268
- /**
269
- * Trigger an internal event.
270
- *
271
- * @param string $event_name
272
- * @param array $arguments
273
- * @return $this
274
- */
275
- private function triggerEvent ($ event_name , ...$ arguments )
252
+ private function triggerEvent (string $ event_name , ...$ arguments ): AuthenticationInterface
276
253
{
277
254
$ property_name = "on_ {$ event_name }" ;
278
255
@@ -284,41 +261,35 @@ private function triggerEvent($event_name, ...$arguments)
284
261
return $ this ;
285
262
}
286
263
287
- /**
288
- * {@inheritdoc}
289
- */
290
- public function onUserAuthenticated (callable $ value )
264
+ public function onUserAuthenticated (callable $ value ): AuthenticationInterface
291
265
{
292
266
$ this ->on_user_authenticated [] = $ value ;
293
267
294
268
return $ this ;
295
269
}
296
270
297
- public function onUserAuthorized (callable $ value )
271
+ public function onUserAuthorized (callable $ value ): AuthenticationInterface
298
272
{
299
273
$ this ->on_user_authorized [] = $ value ;
300
274
301
275
return $ this ;
302
276
}
303
277
304
- public function onUserAuthorizationFailed (callable $ value )
278
+ public function onUserAuthorizationFailed (callable $ value ): AuthenticationInterface
305
279
{
306
280
$ this ->on_user_authorization_failed [] = $ value ;
307
281
308
282
return $ this ;
309
283
}
310
284
311
- /**
312
- * {@inheritdoc}
313
- */
314
- public function onUserSet (callable $ value )
285
+ public function onUserSet (callable $ value ): AuthenticationInterface
315
286
{
316
287
$ this ->on_user_set [] = $ value ;
317
288
318
289
return $ this ;
319
290
}
320
291
321
- public function onUserDeauthenticated (callable $ value )
292
+ public function onUserDeauthenticated (callable $ value ): AuthenticationInterface
322
293
{
323
294
$ this ->on_user_deauthenticated [] = $ value ;
324
295
@@ -330,7 +301,7 @@ public function onUserDeauthenticated(callable $value)
330
301
*
331
302
* {@inheritdoc}
332
303
*/
333
- public function setOnAuthenciatedUserChanged (callable $ value = null )
304
+ public function setOnAuthenciatedUserChanged (callable $ value = null ): AuthenticationInterface
334
305
{
335
306
if (empty ($ value )) {
336
307
throw new InvalidArgumentException ('Value needs to be a callable. ' );
0 commit comments