• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 19165586840

07 Nov 2025 10:29AM UTC coverage: 0.0% (-22.0%) from 22.042%
19165586840

Pull #7514

github

web-flow
Merge e9333c522 into 0edbc37fc
Pull Request #7514: fix(jsonld): read identifier with itemUriTemplate

0 of 6 new or added lines in 1 file covered. (0.0%)

11196 existing lines in 362 files now uncovered.

0 of 49868 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/HttpCache/State/AddHeadersProcessor.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\HttpCache\State;
15

16
use ApiPlatform\Metadata\HttpOperation;
17
use ApiPlatform\Metadata\Operation;
18
use ApiPlatform\State\ProcessorInterface;
19
use Symfony\Component\HttpFoundation\Response;
20

21
/**
22
 * @template T1
23
 * @template T2
24
 *
25
 * @implements ProcessorInterface<T1, T2>
26
 */
27
final class AddHeadersProcessor implements ProcessorInterface
28
{
29
    /**
30
     * @param ProcessorInterface<T1, T2> $decorated
31
     */
32
    public function __construct(
33
        private readonly ProcessorInterface $decorated,
34
        private readonly bool $etag = false,
35
        private readonly ?int $maxAge = null,
36
        private readonly ?int $sharedMaxAge = null,
37
        private readonly ?array $vary = null,
38
        private readonly ?bool $public = null,
39
        private readonly ?int $staleWhileRevalidate = null,
40
        private readonly ?int $staleIfError = null,
41
    ) {
UNCOV
42
    }
×
43

44
    public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
45
    {
UNCOV
46
        $response = $this->decorated->process($data, $operation, $uriVariables, $context);
×
47

48
        if (
UNCOV
49
            !($request = $context['request'] ?? null)
×
UNCOV
50
            || !$request->isMethodCacheable()
×
UNCOV
51
            || !$response instanceof Response
×
UNCOV
52
            || !$operation instanceof HttpOperation
×
53
        ) {
UNCOV
54
            return $response;
×
55
        }
56

UNCOV
57
        if (!($content = $response->getContent()) || !$response->isSuccessful()) {
×
UNCOV
58
            return $response;
×
59
        }
60

UNCOV
61
        $resourceCacheHeaders = $operation->getCacheHeaders() ?? [];
×
62

UNCOV
63
        if ($this->etag && !$response->getEtag()) {
×
UNCOV
64
            $response->setEtag(hash('xxh3', (string) $content));
×
65
        }
66

UNCOV
67
        if (null !== ($maxAge = $resourceCacheHeaders['max_age'] ?? $this->maxAge) && !$response->headers->hasCacheControlDirective('max-age')) {
×
UNCOV
68
            $response->setMaxAge($maxAge);
×
69
        }
70

UNCOV
71
        $vary = $resourceCacheHeaders['vary'] ?? $this->vary;
×
UNCOV
72
        if (null !== $vary) {
×
UNCOV
73
            $response->setVary(array_diff($vary, $response->getVary()), false);
×
74
        }
75

76
        // if the public-property is defined and not yet set; apply it to the response
UNCOV
77
        $public = ($resourceCacheHeaders['public'] ?? $this->public);
×
UNCOV
78
        if (null !== $public && !$response->headers->hasCacheControlDirective('public')) {
×
UNCOV
79
            $public ? $response->setPublic() : $response->setPrivate();
×
80
        }
81

82
        // Cache-Control "s-maxage" is only relevant is resource is not marked as "private"
UNCOV
83
        if (false !== $public && null !== ($sharedMaxAge = $resourceCacheHeaders['shared_max_age'] ?? $this->sharedMaxAge) && !$response->headers->hasCacheControlDirective('s-maxage')) {
×
UNCOV
84
            $response->setSharedMaxAge($sharedMaxAge);
×
85
        }
86

UNCOV
87
        if (null !== ($staleWhileRevalidate = $resourceCacheHeaders['stale_while_revalidate'] ?? $this->staleWhileRevalidate) && !$response->headers->hasCacheControlDirective('stale-while-revalidate')) {
×
88
            $response->headers->addCacheControlDirective('stale-while-revalidate', (string) $staleWhileRevalidate);
×
89
        }
90

UNCOV
91
        if (null !== ($staleIfError = $resourceCacheHeaders['stale_if_error'] ?? $this->staleIfError) && !$response->headers->hasCacheControlDirective('stale-if-error')) {
×
92
            $response->headers->addCacheControlDirective('stale-if-error', (string) $staleIfError);
×
93
        }
94

UNCOV
95
        return $response;
×
96
    }
97
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc