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

nette / routing / 21943387777

12 Feb 2026 10:44AM UTC coverage: 96.919% (+0.03%) from 96.89%
21943387777

push

github

dg
added CLAUDE.md

409 of 422 relevant lines covered (96.92%)

0.97 hits per line

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

94.44
/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
                /** @var array<string, mixed> */
23
                private readonly array $defaults = [],
24
        ) {
25
        }
1✔
26

27

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

39

40
        /**
41
         * Constructs absolute URL from array.
42
         * @param array<string, mixed>  $params
43
         */
44
        public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string
1✔
45
        {
46
                // remove default values; null values are retain
47
                foreach ($this->defaults as $key => $value) {
1✔
48
                        if (isset($params[$key])
1✔
49
                                && (is_scalar($params[$key]) ? (string) $params[$key] : $params[$key]) === (is_scalar($value) ? (string) $value : $value)
1✔
50
                        ) {
51
                                unset($params[$key]);
1✔
52
                        }
53
                }
54

55
                $url = $refUrl->getHostUrl() . $refUrl->getPath();
1✔
56
                $sep = ini_get('arg_separator.input');
1✔
57
                $query = http_build_query($params, '', $sep ? $sep[0] : '&');
1✔
58
                if ($query !== '') {
1✔
59
                        $url .= '?' . $query;
1✔
60
                }
61

62
                return $url;
1✔
63
        }
64

65

66
        /**
67
         * Returns default values.
68
         * @return array<string, mixed>
69
         */
70
        public function getDefaults(): array
71
        {
72
                return $this->defaults;
×
73
        }
74
}
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