-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathChain.php
44 lines (37 loc) · 1.13 KB
/
Chain.php
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
42
43
44
<?php
namespace Http\Message\Authentication;
use Http\Message\Authentication;
use Psr\Http\Message\RequestInterface;
/**
* Authenticate a PSR-7 Request with a multiple authentication methods.
*
* @author Márk Sági-Kazár <[email protected]>
*/
final class Chain implements Authentication
{
/**
* @var Authentication[]
*/
private $authenticationChain = [];
/**
* @param Authentication[] $authenticationChain
*/
public function __construct(array $authenticationChain = [])
{
foreach ($authenticationChain as $authentication) {
if (!$authentication instanceof Authentication) {
throw new \InvalidArgumentException(
'Members of the authentication chain must be of type Http\Message\Authentication'
);
}
}
$this->authenticationChain = $authenticationChain;
}
public function authenticate(RequestInterface $request)
{
foreach ($this->authenticationChain as $authentication) {
$request = $authentication->authenticate($request);
}
return $request;
}
}