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

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

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

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

34.33 hits per line

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

90.91
/src/HttpCache/State/AddTagsProcessor.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\HttpCache\PurgerInterface;
17
use ApiPlatform\Metadata\CollectionOperationInterface;
18
use ApiPlatform\Metadata\HttpOperation;
19
use ApiPlatform\Metadata\IriConverterInterface;
20
use ApiPlatform\Metadata\Operation;
21
use ApiPlatform\Metadata\UrlGeneratorInterface;
22
use ApiPlatform\State\ProcessorInterface;
23
use ApiPlatform\State\UriVariablesResolverTrait;
24
use Symfony\Component\HttpFoundation\Response;
25

26
/**
27
 * Sets the list of resources' IRIs included in this response in the configured cache tag HTTP header and/or "xkey" HTTP headers.
28
 *
29
 * By default the "Cache-Tags" HTTP header is used because it is supported by CloudFlare.
30
 *
31
 * @see https://developers.cloudflare.com/cache/how-to/purge-cache#add-cache-tag-http-response-headers
32
 *
33
 * The "xkey" is used because it is supported by Varnish.
34
 * @see https://docs.varnish-software.com/varnish-cache-plus/vmods/ykey/
35
 *
36
 * @author Kévin Dunglas <dunglas@gmail.com>
37
 */
38
final class AddTagsProcessor implements ProcessorInterface
39
{
40
    use UriVariablesResolverTrait;
41

42
    public function __construct(private readonly ProcessorInterface $decorated, private readonly IriConverterInterface $iriConverter, private readonly ?PurgerInterface $purger = null)
43
    {
UNCOV
44
    }
799✔
45

46
    /**
47
     * Adds the configured HTTP cache tag and "xkey" headers.
48
     */
49
    public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
50
    {
UNCOV
51
        $response = $this->decorated->process($data, $operation, $uriVariables, $context);
792✔
52

53
        if (
UNCOV
54
            !($request = $context['request'] ?? null)
792✔
UNCOV
55
            || !$request->isMethodCacheable()
792✔
UNCOV
56
            || !$response instanceof Response
792✔
UNCOV
57
            || !$operation instanceof HttpOperation
792✔
UNCOV
58
            || !$response->isCacheable()
792✔
59
        ) {
UNCOV
60
            return $response;
263✔
61
        }
62

UNCOV
63
        $resources = $request->attributes->get('_resources', []);
546✔
UNCOV
64
        if ($operation instanceof CollectionOperationInterface) {
546✔
65
            // Allows to purge collections
UNCOV
66
            $uriVariables = $this->getOperationUriVariables($operation, $request->attributes->all(), $operation->getClass());
365✔
UNCOV
67
            $iri = $this->iriConverter->getIriFromResource($operation->getClass(), UrlGeneratorInterface::ABS_PATH, $operation, ['uri_variables' => $uriVariables]);
365✔
68

UNCOV
69
            $resources[$iri] = $iri;
365✔
70
        }
71

UNCOV
72
        if (!$resources) {
546✔
UNCOV
73
            return $response;
42✔
74
        }
75

UNCOV
76
        if (!$this->purger) {
504✔
77
            $response->headers->set('Cache-Tags', implode(',', $resources));
×
78

79
            return $response;
×
80
        }
81

UNCOV
82
        $headers = $this->purger->getResponseHeaders($resources);
504✔
83

UNCOV
84
        foreach ($headers as $key => $value) {
504✔
UNCOV
85
            $response->headers->set($key, $value);
504✔
86
        }
87

UNCOV
88
        return $response;
504✔
89
    }
90
}
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

© 2025 Coveralls, Inc