|
1
|
|
|
<?php |
|
2
|
|
|
namespace JayaCode\Framework\Core\Route; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Class Route |
|
6
|
|
|
* @property array explodePath |
|
7
|
|
|
* @property array ruleMatches |
|
8
|
|
|
* @method get(string $name, string $path, mixed $handle) |
|
9
|
|
|
* @method post(string $name, string $path, mixed $handle) |
|
10
|
|
|
* @method put(string $name, string $path, mixed $handle) |
|
11
|
|
|
* @method delete(string $name, string $path, mixed $handle) |
|
12
|
|
|
* @method head(string $name, string $path, mixed $handle) |
|
13
|
|
|
* @method options(string $name, string $path, mixed $handle) |
|
14
|
|
|
* @method connect(string $name, string $path, mixed $handle) |
|
15
|
|
|
* @package JayaCode\Framework\Core\Route |
|
16
|
|
|
*/ |
|
17
|
|
|
class Route |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
public $key; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
public $path; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var |
|
32
|
|
|
*/ |
|
33
|
|
|
public $handle; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
public $method; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var array |
|
42
|
|
|
*/ |
|
43
|
|
|
public $ruleMatches = array(); |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var |
|
47
|
|
|
*/ |
|
48
|
|
|
public $attributes; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Route constructor. |
|
52
|
|
|
* @param string $key |
|
53
|
|
|
* @param string $path |
|
54
|
|
|
* @param $handle |
|
55
|
|
|
* @param string $method |
|
56
|
|
|
*/ |
|
57
|
3 |
|
public function __construct($key, $path, $handle, $method) |
|
58
|
|
|
{ |
|
59
|
3 |
|
$this->key = $key; |
|
60
|
3 |
|
$this->path = $path; |
|
61
|
3 |
|
$this->handle = $handle; |
|
62
|
3 |
|
$this->method = $method; |
|
63
|
3 |
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param $key |
|
67
|
|
|
* @param $path |
|
68
|
|
|
* @param $handle |
|
69
|
|
|
* @param string $method |
|
70
|
|
|
* @return static |
|
71
|
|
|
*/ |
|
72
|
3 |
|
public static function create($key, $path, $handle, $method = "GET") |
|
73
|
|
|
{ |
|
74
|
3 |
|
return new static($key, $path, $handle, $method); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param $name |
|
79
|
|
|
* @param $arguments |
|
80
|
|
|
* @return Route |
|
81
|
|
|
*/ |
|
82
|
3 |
|
public static function __callStatic($name, $arguments) |
|
83
|
|
|
{ |
|
84
|
3 |
|
if (count($arguments) != 3) { |
|
85
|
|
|
throw new \InvalidArgumentException(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
3 |
|
$method = strtoupper($name); |
|
89
|
3 |
|
return static::create($arguments[0], $arguments[1], $arguments[2], $method); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param $name |
|
94
|
|
|
* @param $value |
|
95
|
|
|
*/ |
|
96
|
3 |
|
public function __set($name, $value) |
|
97
|
|
|
{ |
|
98
|
3 |
|
$this->attributes[$name] = $value; |
|
99
|
3 |
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @param $name |
|
103
|
|
|
* @return mixed |
|
104
|
|
|
*/ |
|
105
|
3 |
|
public function __get($name) |
|
106
|
|
|
{ |
|
107
|
3 |
|
if (!isset($this->attributes[$name])) { |
|
108
|
|
|
throw new \OutOfBoundsException(); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
3 |
|
return $this->attributes[$name]; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|