Passed
Pull Request — 1.x (#125)
by
unknown
02:24
created

FastlyCachePurgeModule::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 13
rs 9.9332
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\QueryRepository\Cdn;
6
7
use BEAR\QueryRepository\PurgerInterface;
8
use Fastly\Api\PurgeApi;
9
use Fastly\Configuration;
10
use GuzzleHttp\Client;
11
use GuzzleHttp\ClientInterface;
12
use Ray\Di\AbstractModule;
13
use Ray\Di\Scope;
14
15
final class FastlyCachePurgeModule extends AbstractModule
16
{
17
    private string $fastlyApiKey;
18
    private string $fastlyServiceId;
19
    private bool $enableSoftPurge;
20
21
    /**
22
     * @SuppressWarnings("PHPMD.BooleanArgumentFlag")
23
     */
24
    public function __construct(
25
        string $fastlyApiKey,
26
        string $fastlyServiceId,
27
        bool $enableSoftPurge = true,
28
        ?AbstractModule $module = null
29
    ) {
30
        $this->fastlyApiKey = $fastlyApiKey;
31
        $this->fastlyServiceId = $fastlyServiceId;
32
        $this->enableSoftPurge = $enableSoftPurge;
33
34
        parent::__construct($module);
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    protected function configure(): void
41
    {
42
        $this->bind(Configuration::class)->annotatedWith(Configuration::class)->toInstance(
43
            Configuration::getDefaultConfiguration()->setApiToken($this->fastlyApiKey)
44
        );
45
        $this->bind(PurgeApi::class)->toConstructor(PurgeApi::class, [
46
            'config' => Configuration::class,
47
        ])->in(Scope::SINGLETON);
48
        $this->bind()->annotatedWith('fastlyServiceId')->toInstance($this->fastlyServiceId);
49
        $this->bind()->annotatedWith('fastlyEnableSoftPurge')->toInstance($this->enableSoftPurge);
50
        $this->bind(ClientInterface::class)->annotatedWith('fastlyApi')
51
            ->toConstructor(Client::class, ['config' => 'fastly_http_client_options']);
52
        $this->bind(PurgerInterface::class)->to(FastlyCachePurger::class);
53
    }
54
}
55