-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
CurrentRoute.php
71 lines (63 loc) · 1.45 KB
/
CurrentRoute.php
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
<?php
declare(strict_types=1);
namespace Yiisoft\Router;
use Psr\Http\Message\UriInterface;
use RuntimeException;
/**
* Holds information about current route e.g. matched last.
*/
final class CurrentRoute
{
/**
* Current Route
*
* @var RouteParametersInterface|null
*/
private ?RouteParametersInterface $route = null;
/**
* Current URI
*
* @var UriInterface|null
*/
private ?UriInterface $uri = null;
/**
* Returns the current Route object
*
* @return RouteParametersInterface|null current route
*/
public function getRoute(): ?RouteParametersInterface
{
return $this->route;
}
/**
* Returns current URI
*
* @return UriInterface|null current URI
*/
public function getUri(): ?UriInterface
{
return $this->uri;
}
/**
* @param RouteParametersInterface $route
*/
public function setRoute(RouteParametersInterface $route): void
{
if ($this->route === null) {
$this->route = $route;
return;
}
throw new RuntimeException('Can not set route since it was already set.');
}
/**
* @param UriInterface $uri
*/
public function setUri(UriInterface $uri): void
{
if ($this->uri === null) {
$this->uri = $uri;
return;
}
throw new RuntimeException('Can not set URI since it was already set.');
}
}