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

api-platform / core / 13925245599

18 Mar 2025 02:06PM UTC coverage: 61.074% (-0.9%) from 61.973%
13925245599

Pull #7031

github

web-flow
Merge 8990d8b26 into 7cb5a6db8
Pull Request #7031: fix: header parameter should be case insensitive

3 of 4 new or added lines in 1 file covered. (75.0%)

167 existing lines in 27 files now uncovered.

11314 of 18525 relevant lines covered (61.07%)

51.02 hits per line

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

73.33
/src/Hydra/EventListener/AddLinkHeaderListener.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\Hydra\EventListener;
15

16
use ApiPlatform\Api\UrlGeneratorInterface as LegacyUrlGeneratorInterface;
17
use ApiPlatform\JsonLd\ContextBuilder;
18
use ApiPlatform\Metadata\UrlGeneratorInterface;
19
use ApiPlatform\State\Util\CorsTrait;
20
use Psr\Link\EvolvableLinkProviderInterface;
21
use Symfony\Component\HttpKernel\Event\ResponseEvent;
22
use Symfony\Component\WebLink\GenericLinkProvider;
23
use Symfony\Component\WebLink\Link;
24

25
/**
26
 * Adds the HTTP Link header pointing to the Hydra documentation.
27
 *
28
 * @deprecated use ApiPlatform\Hydra\State\HydraLinkProcessor instead
29
 *
30
 * @author Kévin Dunglas <dunglas@gmail.com>
31
 */
32
final class AddLinkHeaderListener
33
{
34
    use CorsTrait;
35

36
    public function __construct(private readonly UrlGeneratorInterface|LegacyUrlGeneratorInterface $urlGenerator)
37
    {
38
    }
6✔
39

40
    /**
41
     * Sends the Hydra header on each response.
42
     */
43
    public function onKernelResponse(ResponseEvent $event): void
44
    {
45
        $request = $event->getRequest();
6✔
46
        if (($operation = $request->attributes->get('_api_operation')) && 'api_platform.symfony.main_controller' === $operation->getController()) {
6✔
UNCOV
47
            return;
×
48
        }
49

50
        // Prevent issues with NelmioCorsBundle
51
        if ($this->isPreflightRequest($request)) {
6✔
52
            return;
3✔
53
        }
54

55
        $apiDocUrl = $this->urlGenerator->generate('api_doc', ['_format' => 'jsonld'], UrlGeneratorInterface::ABS_URL);
3✔
56
        $apiDocLink = new Link(ContextBuilder::HYDRA_NS.'apiDocumentation', $apiDocUrl);
3✔
57
        $linkProvider = $request->attributes->get('_api_platform_links', new GenericLinkProvider());
3✔
58

59
        if (!$linkProvider instanceof EvolvableLinkProviderInterface) {
3✔
60
            return;
×
61
        }
62

63
        foreach ($linkProvider->getLinks() as $link) {
3✔
UNCOV
64
            if ($link->getHref() === $apiDocUrl) {
×
UNCOV
65
                return;
×
66
            }
67
        }
68

69
        $request->attributes->set('_api_platform_links', $linkProvider->withLink($apiDocLink));
3✔
70
    }
71
}
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