-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathRouterInterface.php
More file actions
132 lines (113 loc) · 3.83 KB
/
RouterInterface.php
File metadata and controls
132 lines (113 loc) · 3.83 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php declare(strict_types=1);
/**
* Created by PhpStorm.
* User: inhere
* Date: 2017/7/16
* Time: 下午10:43
*/
namespace Inhere\Route;
use Countable;
use IteratorAggregate;
/**
* Interface RouterInterface
*
* @package Inhere\Route
*/
interface RouterInterface extends IteratorAggregate, Countable
{
/** match result status list */
public const FOUND = 1;
public const NOT_FOUND = 2;
public const METHOD_NOT_ALLOWED = 3;
public const FAV_ICON = '/favicon.ico';
public const DEFAULT_REGEX = '[^/]+';
/** supported method list */
public const GET = 'GET';
public const POST = 'POST';
public const PUT = 'PUT';
public const PATCH = 'PATCH';
public const DELETE = 'DELETE';
public const OPTIONS = 'OPTIONS';
public const HEAD = 'HEAD';
public const COPY = 'COPY';
public const PURGE = 'PURGE';
public const LINK = 'LINK';
public const UNLINK = 'UNLINK';
public const LOCK = 'LOCK';
public const UNLOCK = 'UNLOCK';
public const SEARCH = 'SEARCH';
public const CONNECT = 'CONNECT';
public const TRACE = 'TRACE';
/** supported methods name list */
public const METHODS_ARRAY = [
'GET',
'POST',
'PUT',
'PATCH',
'DELETE',
'OPTIONS',
'HEAD',
'CONNECT'
// 'COPY', 'PURGE', 'LINK', 'UNLINK', 'LOCK', 'UNLOCK', 'VIEW', 'SEARCH', 'TRACE',
];
// ,COPY,PURGE,LINK,UNLINK,LOCK,UNLOCK,VIEW,SEARCH,TRACE';
/** supported methods name string */
public const METHODS_STRING = ',GET,POST,PUT,PATCH,DELETE,OPTIONS,HEAD,CONNECT,';
/** the matched result index key */
public const INDEX_STATUS = 0;
public const INDEX_PATH = 1;
public const INDEX_INFO = 2;
/**
* add a route to the router.
*
* @param string $method Request method name. eg 'GET'
* @param string $path The route path. eg '/users'
* @param mixed $handler The route handler. allow: string, array, object
* @param array $pathParams The route path var bind. eg. [ 'id' => '[0-9]+', ]
* @param array $opts Extra options
* - name: string
* - ... more
*
* @return Route
*/
public function add(string $method, string $path, $handler, array $pathParams = [], array $opts = []): Route;
/**
* add a Route to the router
*
* @param Route $route
*
* @return Route
*/
public function addRoute(Route $route): Route;
/**
* @param array|string $methods The match request method(s). e.g ['get','post']
* @param string $path The route path string. is allow empty string. eg: '/user/login'
* @param callable|string $handler
* @param array $pathParams route path var bind. eg. [ 'id' => '[0-9]+', ]
* @param array $opts some option data
* [
* 'defaults' => [ 'id' => 10, ],
* 'domains' => [ 'a-domain.com', '*.b-domain.com'],
* 'schemas' => ['https'],
* ]
*/
public function map($methods, string $path, $handler, array $pathParams = [], array $opts = []): void;
/**
* find the matched route info for the given request uri path
*
* @param string $method
* @param string $path
*
* @return array
*
* [self::NOT_FOUND, $path, null]
* [self::METHOD_NOT_ALLOWED, $path, ['GET', 'OTHER_METHODS_ARRAY']]
* [self::FOUND, $path, array () // routeData ]
*
*/
public function match(string $path, string $method = 'GET'): array;
/**
* @return array
*/
public function getChains(): array;
}