-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbstractCacheSettings.php
55 lines (45 loc) · 1.34 KB
/
AbstractCacheSettings.php
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
48
49
50
51
52
53
54
55
<?php
declare(strict_types=1);
namespace AnzuSystems\Contracts\Response\Cache;
use AnzuSystems\Contracts\AnzuApp;
use Symfony\Component\HttpFoundation\Response;
abstract class AbstractCacheSettings implements CacheSettingsInterface
{
public function __construct(
protected int $cacheTtl,
) {
}
public function setCache(Response $response): Response
{
$response->setPublic();
$response->setMaxAge(0);
$response->headers->set('X-Cache-Control-TTL', (string) $this->cacheTtl);
$response->headers->set('X-Remove-Cookie', '1');
$response->headers->remove('Expires');
$this->setXKeys($response);
return $response;
}
public static function buildXKeyFromObject(object $data): string
{
return '';
}
public static function getProjectXkey(): string
{
return 'anzu-' . AnzuApp::getAppNamespace() . '-' . AnzuApp::getAppSystem();
}
/**
* @return list<string>
*/
protected function getXKeys(): array
{
return [];
}
private function setXKeys(Response $response): void
{
$xKeys = [
self::getProjectXkey(),
...array_map(fn (string $key) => self::getProjectXkey() . '-' . $key, $this->getXKeys()),
];
$response->headers->set('xkey', implode(' ', $xKeys));
}
}