-
-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathSimpleRouter.php
More file actions
41 lines (31 loc) · 992 Bytes
/
SimpleRouter.php
File metadata and controls
41 lines (31 loc) · 992 Bytes
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
<?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;
use function is_string;
/**
* The bidirectional route for trivial routing via query parameters.
*/
final class SimpleRouter extends Nette\Routing\SimpleRouter implements Nette\Routing\Router
{
private const PresenterKey = 'presenter';
public function __construct(array|string $defaults = [])
{
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::PresenterKey => $presenter,
'action' => $action === '' ? Application\UI\Presenter::DefaultAction : $action,
];
}
parent::__construct($defaults);
}
}