Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8be572a

Browse files
create route class for save route
1 parent 41137b4 commit 8be572a

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

‎System/Router/Route.php‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
/**
4+
*
5+
* This file is part of simple-mvc-rest-api for PHP.
6+
*
7+
*/
8+
namespace Router;
9+
10+
final class Route {
11+
12+
/**
13+
* Http Method.
14+
*
15+
* @var string
16+
*/
17+
private $method;
18+
19+
/**
20+
* The path for this route.
21+
*
22+
* @var string
23+
*/
24+
private $pattern;
25+
26+
/**
27+
* The action, controller, callable. this route points to.
28+
*
29+
* @var mixed
30+
*/
31+
private $callback;
32+
33+
/**
34+
* Allows these HTTP methods.
35+
*
36+
* @var array
37+
*/
38+
private $list_method = ['GET', 'POST', 'PUT', 'DELETE', 'OPTION'];
39+
40+
/**
41+
* construct function
42+
*/
43+
public function __construct(String $method, String $pattern, $callback) {
44+
$this->method = $this->validateMethod(strtoupper($method));
45+
$this->pattern = $pattern;
46+
$this->callback = $callback;
47+
}
48+
49+
/**
50+
* check valid method
51+
*/
52+
private function validateMethod(string $method) {
53+
if (in_array($method, $this->list_method))
54+
return $method;
55+
56+
throw new Exception('Invalid Method Name');
57+
}
58+
59+
/**
60+
* get method
61+
*/
62+
public function getMethod() {
63+
return $this->method;
64+
}
65+
66+
/**
67+
* get pattern
68+
*/
69+
public function getPattern() {
70+
return $this->pattern;
71+
}
72+
73+
/**
74+
* get callback
75+
*/
76+
public function getCallback() {
77+
return $this->callback;
78+
}
79+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /