1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace BEAR\QueryRepository; |
6
|
|
|
|
7
|
|
|
use BEAR\Resource\AbstractUri; |
8
|
|
|
use BEAR\Resource\ResourceObject; |
9
|
|
|
|
10
|
|
|
use function array_key_exists; |
11
|
|
|
use function array_merge; |
12
|
|
|
use function array_unique; |
13
|
|
|
use function explode; |
14
|
|
|
use function http_build_query; |
15
|
|
|
use function implode; |
16
|
|
|
use function sprintf; |
17
|
|
|
use function str_replace; |
18
|
|
|
|
19
|
|
|
final class SurrogateKeys |
20
|
|
|
{ |
21
|
|
|
/** @var list<string> */ |
|
|
|
|
22
|
|
|
private array $surrogateKeys; |
23
|
|
|
private readonly UriTagInterface $uriTag; |
24
|
|
|
|
25
|
|
|
public function __construct(AbstractUri $uri) |
26
|
|
|
{ |
27
|
|
|
$path = str_replace(['/', '\\'], '_', $uri->path); |
28
|
|
|
$uriKey = sprintf('%s_%s', $path, http_build_query($uri->query)); |
29
|
|
|
$this->surrogateKeys = [$uriKey]; |
|
|
|
|
30
|
|
|
$this->uriTag = new UriTag(); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Add etag of embedded resource |
35
|
|
|
*/ |
36
|
|
|
public function addTag(ResourceObject $ro): void |
37
|
|
|
{ |
38
|
|
|
$this->surrogateKeys[] = ($this->uriTag)($ro->uri); |
39
|
|
|
if (array_key_exists(Header::SURROGATE_KEY, $ro->headers)) { |
40
|
|
|
$this->surrogateKeys = array_merge($this->surrogateKeys, explode(' ', $ro->headers[Header::SURROGATE_KEY])); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function setSurrogateHeader(ResourceObject $ro): void |
45
|
|
|
{ |
46
|
|
|
$key = implode(' ', array_unique($this->surrogateKeys)); |
47
|
|
|
$wasSetManually = isset($ro->headers[Header::SURROGATE_KEY]); |
48
|
|
|
if ($wasSetManually) { |
49
|
|
|
$ro->headers[Header::SURROGATE_KEY] .= ' ' . $key; |
50
|
|
|
|
51
|
|
|
return; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$ro->headers[Header::SURROGATE_KEY] = $key; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths