• 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

100.0
/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
    {
UNCOV
38
    }
959✔
39

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

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

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

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

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

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

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

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

© 2025 Coveralls, Inc