Completed
Pull Request — master (#343)
by Luc
06:52
created

ApiKeyPsr7RequestAuthorizer::authorize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace CultuurNet\UDB3\Http;
4
5
use Psr\Http\Message\RequestInterface;
6
use ValueObjects\StringLiteral\StringLiteral;
7
8
class ApiKeyPsr7RequestAuthorizer implements Psr7RequestAuthorizerInterface
9
{
10
    /**
11
     * @todo Is it possible to reuse ApiKey from 'cultuurnet/udb3-api-guard'?
12
     * @var StringLiteral
13
     */
14
    private $apiKey;
15
16
    /**
17
     * It is also possible to work without ApiKey, so the ApiKey can be null.
18
     * This can only be covered by setting default null value.
19
     *
20
     * @param StringLiteral $apiKey
21
     */
22
    public function __construct(StringLiteral $apiKey)
23
    {
24
        $this->apiKey = $apiKey;
25
    }
26
27
    /**
28
     * @inheritdoc
29
     */
30
    public function authorize(RequestInterface $request)
31
    {
32
        return $request->withHeader("X-Api-Key", "{$this->apiKey}");
33
    }
34
}