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 FastlyPurgeModule extends AbstractModule |
16
|
|
|
{ |
17
|
|
|
/** @SuppressWarnings("PHPMD.BooleanArgumentFlag") */ |
18
|
|
|
public function __construct( |
19
|
|
|
private string $fastlyApiKey, |
20
|
|
|
private string $fastlyServiceId, |
21
|
|
|
private bool $enableSoftPurge = true, |
22
|
|
|
AbstractModule|null $module = null, |
23
|
|
|
) { |
24
|
|
|
parent::__construct($module); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** {@inheritdoc} */ |
28
|
|
|
protected function configure(): void |
29
|
|
|
{ |
30
|
|
|
$this->bind(Configuration::class)->annotatedWith(Configuration::class)->toInstance( |
31
|
|
|
Configuration::getDefaultConfiguration()->setApiToken($this->fastlyApiKey), |
32
|
|
|
); |
33
|
|
|
$this->bind(PurgeApi::class)->toConstructor(PurgeApi::class, [ |
34
|
|
|
'config' => Configuration::class, |
35
|
|
|
])->in(Scope::SINGLETON); |
36
|
|
|
$this->bind()->annotatedWith('fastlyServiceId')->toInstance($this->fastlyServiceId); |
37
|
|
|
$this->bind()->annotatedWith('fastlyEnableSoftPurge')->toInstance($this->enableSoftPurge); |
38
|
|
|
$this->bind(ClientInterface::class)->annotatedWith('fastlyApi') |
39
|
|
|
->toConstructor(Client::class, ['config' => 'fastly_http_client_options']); |
40
|
|
|
$this->bind(PurgerInterface::class)->to(FastlyCachePurger::class); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|