-
-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathSimpleRouter.php
More file actions
74 lines (57 loc) · 1.8 KB
/
SimpleRouter.php
File metadata and controls
74 lines (57 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Nette\Application\Routers;
use Nette;
use Nette\Application;
/**
* The bidirectional route for trivial routing via query parameters.
*/
final class SimpleRouter extends Nette\Routing\SimpleRouter implements Nette\Routing\Router
{
private const
PRESENTER_KEY = 'presenter',
MODULE_KEY = 'module';
/** @var int */
private $flags;
public function __construct($defaults = [], int $flags = 0)
{
if (is_string($defaults)) {
[$presenter, $action] = Nette\Application\Helpers::splitName($defaults);
if (!$presenter) {
throw new Nette\InvalidArgumentException("Argument must be array or string in format Presenter:action, '$defaults' given.");
}
$defaults = [
self::PRESENTER_KEY => $presenter,
'action' => $action === '' ? Application\UI\Presenter::DEFAULT_ACTION : $action,
];
}
if (isset($defaults[self::MODULE_KEY])) {
throw new Nette\DeprecatedException(__METHOD__ . '() parameter module is deprecated, use RouteList::withModule() instead.');
} elseif ($flags) {
trigger_error(__METHOD__ . '() parameter $flags is deprecated, use RouteList::add(..., $flags) instead.', E_USER_DEPRECATED);
}
$this->flags = $flags;
parent::__construct($defaults);
}
/**
* Constructs absolute URL from array.
*/
public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string
{
if ($this->flags & self::ONE_WAY) {
return null;
}
return parent::constructUrl($params, $refUrl);
}
/** @deprecated */
public function getFlags(): int
{
trigger_error(__METHOD__ . '() is deprecated.', E_USER_DEPRECATED);
return $this->flags;
}
}
interface_exists(Nette\Application\IRouter::class);