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

nette / routing / 15763612701

19 Jun 2025 05:45PM UTC coverage: 95.508% (+0.01%) from 95.498%
15763612701

push

github

dg
typo

404 of 423 relevant lines covered (95.51%)

0.96 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
        private array $defaults;
22

23

24
        public function __construct(array $defaults = [])
1✔
25
        {
26
                $this->defaults = $defaults;
1✔
27
        }
1✔
28

29

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

40

41
        /**
42
         * Constructs absolute URL from array.
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]) && $params[$key] == $value) { // default value may be object, intentionally ==
1✔
49
                                unset($params[$key]);
1✔
50
                        }
51
                }
52

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

60
                return $url;
1✔
61
        }
62

63

64
        /**
65
         * Returns default values.
66
         */
67
        public function getDefaults(): array
68
        {
69
                return $this->defaults;
×
70
        }
71
}
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