|
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
|
|
|
|