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

api-platform / core / 6067528200

04 Sep 2023 12:12AM UTC coverage: 36.875% (-21.9%) from 58.794%
6067528200

Pull #5791

github

web-flow
Merge 64157e578 into d09cfc9d2
Pull Request #5791: fix: strip down any sql function name

3096 of 3096 new or added lines in 205 files covered. (100.0%)

9926 of 26918 relevant lines covered (36.87%)

6.5 hits per line

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

86.67
/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;
17
use ApiPlatform\JsonLd\ContextBuilder;
18
use ApiPlatform\Util\CorsTrait;
19
use Psr\Link\EvolvableLinkProviderInterface;
20
use Symfony\Component\HttpKernel\Event\ResponseEvent;
21
use Symfony\Component\WebLink\GenericLinkProvider;
22
use Symfony\Component\WebLink\Link;
23

24
/**
25
 * Adds the HTTP Link header pointing to the Hydra documentation.
26
 *
27
 * @author Kévin Dunglas <dunglas@gmail.com>
28
 */
29
final class AddLinkHeaderListener
30
{
31
    use CorsTrait;
32

33
    public function __construct(private readonly UrlGeneratorInterface $urlGenerator)
34
    {
35
    }
81✔
36

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

47
        // Prevent issues with NelmioCorsBundle
48
        if ($this->isPreflightRequest($request)) {
57✔
49
            return;
3✔
50
        }
51

52
        $apiDocUrl = $this->urlGenerator->generate('api_doc', ['_format' => 'jsonld'], UrlGeneratorInterface::ABS_URL);
54✔
53
        $apiDocLink = new Link(ContextBuilder::HYDRA_NS.'apiDocumentation', $apiDocUrl);
54✔
54
        $linkProvider = $request->attributes->get('_links', new GenericLinkProvider());
54✔
55

56
        if (!$linkProvider instanceof EvolvableLinkProviderInterface) {
54✔
57
            return;
30✔
58
        }
59

60
        foreach ($linkProvider->getLinks() as $link) {
30✔
61
            if ($link->getHref() === $apiDocUrl) {
3✔
62
                return;
×
63
            }
64
        }
65

66
        $request->attributes->set('_links', $linkProvider->withLink($apiDocLink));
30✔
67
    }
68
}
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