-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCompositeMethod.php
More file actions
41 lines (36 loc) · 1.05 KB
/
CompositeMethod.php
File metadata and controls
41 lines (36 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace WebmanTech\Auth\Authentication\Method;
use WebmanTech\Auth\Interfaces\AuthenticationMethodInterface;
use WebmanTech\Auth\Interfaces\IdentityInterface;
use WebmanTech\CommonUtils\Request;
class CompositeMethod implements AuthenticationMethodInterface
{
public function __construct(protected array $methods)
{
foreach ($this->methods as $method) {
if (!$method instanceof AuthenticationMethodInterface) {
throw new \InvalidArgumentException('$method must be ' . AuthenticationMethodInterface::class);
}
}
}
/**
* @inheritDoc
*/
public function authenticate(Request $request): ?IdentityInterface
{
foreach ($this->methods as $method) {
$identity = $method->authenticate($request);
if ($identity !== null) {
return $identity;
}
}
return null;
}
/**
* @return AuthenticationMethodInterface[]
*/
public function getMethods(): array
{
return $this->methods;
}
}