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

api-platform / core / 3713134090

pending completion
3713134090

Pull #5254

github

GitHub
Merge b2ec54b3c into ac711530f
Pull Request #5254: [OpenApi] Add ApiResource::openapi and deprecate openapiContext

197 of 197 new or added lines in 5 files covered. (100.0%)

7493 of 12362 relevant lines covered (60.61%)

67.56 hits per line

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

80.0
/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 Symfony\Component\HttpKernel\Event\ResponseEvent;
20
use Symfony\Component\WebLink\GenericLinkProvider;
21
use Symfony\Component\WebLink\Link;
22

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

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

36
    /**
37
     * Sends the Hydra header on each response.
38
     */
39
    public function onKernelResponse(ResponseEvent $event): void
40
    {
41
        $request = $event->getRequest();
647✔
42
        // Prevent issues with NelmioCorsBundle
43
        if ($this->isPreflightRequest($request)) {
647✔
44
            return;
×
45
        }
46

47
        $apiDocUrl = $this->urlGenerator->generate('api_doc', ['_format' => 'jsonld'], UrlGeneratorInterface::ABS_URL);
647✔
48
        $link = new Link(ContextBuilder::HYDRA_NS.'apiDocumentation', $apiDocUrl);
647✔
49

50
        if (null === $linkProvider = $request->attributes->get('_links')) {
647✔
51
            $request->attributes->set('_links', new GenericLinkProvider([$link]));
647✔
52

53
            return;
647✔
54
        }
55
        $request->attributes->set('_links', $linkProvider->withLink($link));
×
56
    }
57
}
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