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

nette / routing / 20532404379

27 Dec 2025 01:21AM UTC coverage: 95.498% (-0.01%) from 95.508%
20532404379

push

github

dg
typo

403 of 422 relevant lines covered (95.5%)

0.95 hits per line

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

94.12
/src/Routing/SimpleRouter.php
1
<?php
2

3
/**
4
 * This file is part of the Nette Framework (https://nette.org)
5
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6
 */
7

8
declare(strict_types=1);
9

10
namespace Nette\Routing;
11

12
use Nette;
13
use function http_build_query, ini_get, is_scalar;
14

15

16
/**
17
 * The bidirectional route for trivial routing via query parameters.
18
 */
19
class SimpleRouter implements Router
20
{
21
        public function __construct(
1✔
22
                private readonly array $defaults = [],
23
        ) {
24
        }
1✔
25

26

27
        /**
28
         * Maps HTTP request to an array.
29
         */
30
        public function match(Nette\Http\IRequest $httpRequest): ?array
1✔
31
        {
32
                return $httpRequest->getUrl()->getPathInfo() === ''
1✔
33
                        ? $httpRequest->getQuery() + $this->defaults
1✔
34
                        : null;
1✔
35
        }
36

37

38
        /**
39
         * Constructs absolute URL from array.
40
         */
41
        public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string
1✔
42
        {
43
                // remove default values; null values are retain
44
                foreach ($this->defaults as $key => $value) {
1✔
45
                        if (isset($params[$key]) && $params[$key] == $value) { // default value may be object, intentionally ==
1✔
46
                                unset($params[$key]);
1✔
47
                        }
48
                }
49

50
                $url = $refUrl->getHostUrl() . $refUrl->getPath();
1✔
51
                $sep = ini_get('arg_separator.input');
1✔
52
                $query = http_build_query($params, '', $sep ? $sep[0] : '&');
1✔
53
                if ($query !== '') {
1✔
54
                        $url .= '?' . $query;
1✔
55
                }
56

57
                return $url;
1✔
58
        }
59

60

61
        /**
62
         * Returns default values.
63
         */
64
        public function getDefaults(): array
65
        {
66
                return $this->defaults;
×
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

© 2025 Coveralls, Inc