|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Kambo\Router\Route\Route; |
|
5
|
|
|
|
|
6
|
|
|
use Kambo\Router\Route\Route; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class representing the base Route |
|
10
|
|
|
* |
|
11
|
|
|
* @package Kambo\Router\Route\Route |
|
12
|
|
|
* @author Bohuslav Simek <[email protected]> |
|
13
|
|
|
* @license MIT |
|
14
|
|
|
*/ |
|
15
|
|
|
class Base implements Route |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Route methog, eg.: GET, POST, ... |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
private $method; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Route handler, can be callable or array, this is connected |
|
26
|
|
|
* with the selected dispatcher. |
|
27
|
|
|
* |
|
28
|
|
|
* @var mixed |
|
29
|
|
|
*/ |
|
30
|
|
|
private $handler; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Route url eg. /foo/bar |
|
34
|
|
|
* |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
private $url; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Route constructor |
|
41
|
|
|
* |
|
42
|
|
|
* @param String $method |
|
43
|
|
|
* @param String $url |
|
44
|
|
|
* @param Mixed $handler |
|
45
|
|
|
*/ |
|
46
|
|
|
public function __construct(string $method, string $url, $handler) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->method = $method; |
|
49
|
|
|
$this->handler = $handler; |
|
50
|
|
|
$this->url = $url; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Sets route method |
|
55
|
|
|
* |
|
56
|
|
|
* @param string $method route method |
|
57
|
|
|
* |
|
58
|
|
|
* @return self for fluent interface |
|
59
|
|
|
*/ |
|
60
|
|
|
public function setMethod(string $method) : Route |
|
61
|
|
|
{ |
|
62
|
|
|
$this->method = $method; |
|
63
|
|
|
|
|
64
|
|
|
return $this; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Get route method |
|
69
|
|
|
* |
|
70
|
|
|
* @return string |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getMethod() : string |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->method; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Sets URL for route |
|
79
|
|
|
* |
|
80
|
|
|
* @param mixed $url route url |
|
81
|
|
|
* |
|
82
|
|
|
* @return self for fluent interface |
|
83
|
|
|
*/ |
|
84
|
|
|
public function setUrl(string $url) : Route |
|
85
|
|
|
{ |
|
86
|
|
|
$this->url = $url; |
|
87
|
|
|
|
|
88
|
|
|
return $this; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Get URL of route |
|
93
|
|
|
* |
|
94
|
|
|
* @return string |
|
95
|
|
|
*/ |
|
96
|
|
|
public function getUrl() : string |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->url; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Sets handler that will be executed if the url will match the route. |
|
103
|
|
|
* |
|
104
|
|
|
* @param mixed $handler handler which will be executed if the url will |
|
105
|
|
|
* match the route |
|
106
|
|
|
* |
|
107
|
|
|
* @return self for fluent interface |
|
108
|
|
|
*/ |
|
109
|
|
|
public function setHandler($handler) |
|
110
|
|
|
{ |
|
111
|
|
|
$this->handler = $handler; |
|
112
|
|
|
|
|
113
|
|
|
return $this; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Get handler |
|
118
|
|
|
* |
|
119
|
|
|
* @return mixed |
|
120
|
|
|
*/ |
|
121
|
|
|
public function getHandler() |
|
122
|
|
|
{ |
|
123
|
|
|
return $this->handler; |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|