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

api-platform / core / 14726067612

29 Apr 2025 07:47AM UTC coverage: 23.443% (+15.2%) from 8.252%
14726067612

push

github

web-flow
feat(symfony): Autoconfigure classes using `#[ApiResource]` attribute (#6943)

0 of 12 new or added lines in 4 files covered. (0.0%)

3578 existing lines in 159 files now uncovered.

11517 of 49127 relevant lines covered (23.44%)

54.29 hits per line

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

88.24
/src/Symfony/Routing/Router.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\Symfony\Routing;
15

16
use ApiPlatform\Metadata\UrlGeneratorInterface;
17
use Symfony\Component\HttpFoundation\Request;
18
use Symfony\Component\Routing\RequestContext;
19
use Symfony\Component\Routing\RouteCollection;
20
use Symfony\Component\Routing\RouterInterface;
21

22
/**
23
 * Symfony router decorator.
24
 *
25
 * @author Kévin Dunglas <dunglas@gmail.com>
26
 */
27
final class Router implements RouterInterface, UrlGeneratorInterface
28
{
29
    public const CONST_MAP = [
30
        UrlGeneratorInterface::ABS_URL => RouterInterface::ABSOLUTE_URL,
31
        UrlGeneratorInterface::ABS_PATH => RouterInterface::ABSOLUTE_PATH,
32
        UrlGeneratorInterface::REL_PATH => RouterInterface::RELATIVE_PATH,
33
        UrlGeneratorInterface::NET_PATH => RouterInterface::NETWORK_PATH,
34
    ];
35

36
    public function __construct(private readonly RouterInterface $router, private readonly int $urlGenerationStrategy = self::ABS_PATH)
37
    {
38
    }
1,548✔
39

40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function setContext(RequestContext $context): void
44
    {
UNCOV
45
        $this->router->setContext($context);
×
46
    }
47

48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function getContext(): RequestContext
52
    {
UNCOV
53
        return $this->router->getContext();
×
54
    }
55

56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function getRouteCollection(): RouteCollection
60
    {
61
        return $this->router->getRouteCollection();
27✔
62
    }
63

64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function match(string $pathInfo): array
68
    {
69
        $baseContext = $this->router->getContext();
223✔
70
        $baseUrl = $baseContext->getBaseUrl();
223✔
71
        if (str_starts_with($pathInfo, $baseUrl)) {
223✔
72
            $pathInfo = substr($pathInfo, \strlen($baseUrl));
223✔
73
        }
74

75
        $request = Request::create($pathInfo, Request::METHOD_GET, [], [], [], ['HTTP_HOST' => $baseContext->getHost()]);
223✔
76
        $context = (new RequestContext())->fromRequest($request);
223✔
77
        $context->setPathInfo($pathInfo);
223✔
78
        $context->setScheme($baseContext->getScheme());
223✔
79
        $context->setHost($baseContext->getHost());
223✔
80

81
        try {
82
            $this->router->setContext($context);
223✔
83

84
            return $this->router->match($request->getPathInfo());
223✔
85
        } finally {
86
            $this->router->setContext($baseContext);
223✔
87
        }
88
    }
89

90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function generate(string $name, array $parameters = [], ?int $referenceType = null): string
94
    {
95
        return $this->router->generate($name, $parameters, self::CONST_MAP[$referenceType ?? $this->urlGenerationStrategy]);
1,479✔
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