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

nette / application / 20834855301

08 Jan 2026 10:54PM UTC coverage: 84.605% (+1.7%) from 82.856%
20834855301

push

github

dg
added CLAUDE.md

1940 of 2293 relevant lines covered (84.61%)

0.85 hits per line

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

94.74
/src/Application/Routers/CliRouter.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\Application\Routers;
11

12
use Nette;
13
use function is_array;
14

15

16
/**
17
 * The unidirectional router for CLI. (experimental)
18
 */
19
final class CliRouter implements Nette\Routing\Router
20
{
21
        private const PresenterKey = 'action';
22

23

24
        public function __construct(
1✔
25
                /** @var array<string, mixed> */
26
                private readonly array $defaults = [],
27
        ) {
28
        }
1✔
29

30

31
        /**
32
         * Maps command line arguments to an array.
33
         */
34
        public function match(Nette\Http\IRequest $httpRequest): ?array
1✔
35
        {
36
                if (empty($_SERVER['argv']) || !is_array($_SERVER['argv'])) {
1✔
37
                        return null;
1✔
38
                }
39

40
                $names = [self::PresenterKey];
1✔
41
                $params = $this->defaults;
1✔
42
                $args = $_SERVER['argv'];
1✔
43
                array_shift($args);
1✔
44
                $args[] = '--';
1✔
45

46
                foreach ($args as $arg) {
1✔
47
                        $opt = preg_replace('#/|-+#A', '', $arg);
1✔
48
                        if ($opt === $arg) {
1✔
49
                                if (isset($flag) || $flag = array_shift($names)) {
1✔
50
                                        $params[$flag] = $arg;
1✔
51
                                } else {
52
                                        $params[] = $arg;
1✔
53
                                }
54

55
                                $flag = null;
1✔
56
                                continue;
1✔
57
                        }
58

59
                        if (isset($flag)) {
1✔
60
                                $params[$flag] = true;
1✔
61
                                $flag = null;
1✔
62
                        }
63

64
                        if ($opt === '') {
1✔
65
                                continue;
1✔
66
                        }
67

68
                        $pair = explode('=', $opt, 2);
1✔
69
                        if (isset($pair[1])) {
1✔
70
                                $params[$pair[0]] = $pair[1];
1✔
71
                        } else {
72
                                $flag = $pair[0];
1✔
73
                        }
74
                }
75

76
                if (!isset($params[self::PresenterKey])) {
1✔
77
                        throw new Nette\InvalidStateException('Missing presenter & action in route definition.');
×
78
                }
79

80
                [$module, $presenter] = Nette\Application\Helpers::splitName($params[self::PresenterKey]);
1✔
81
                if ($module !== '') {
1✔
82
                        $params[self::PresenterKey] = $presenter;
1✔
83
                        $presenter = $module;
1✔
84
                }
85

86
                $params['presenter'] = $presenter;
1✔
87

88
                return $params;
1✔
89
        }
90

91

92
        /**
93
         * This router is only unidirectional.
94
         */
95
        public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string
1✔
96
        {
97
                return null;
1✔
98
        }
99

100

101
        /**
102
         * Returns default values.
103
         * @return array<string, mixed>
104
         */
105
        public function getDefaults(): array
106
        {
107
                return $this->defaults;
×
108
        }
109
}
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