blob: 71002bb179a5382dd3ad8baf241dc776444d5ca3 (
plain)
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
45
46
47
|
<?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 <mark.sagikazar@gmail.com>
*/
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;
}
/**
* {@inheritdoc}
*/
public function authenticate(RequestInterface $request)
{
foreach ($this->authenticationChain as $authentication) {
$request = $authentication->authenticate($request);
}
return $request;
}
}
|