-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRouteInterface.php
191 lines (174 loc) · 5.33 KB
/
RouteInterface.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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php declare(strict_types=1);
namespace PhpSlides\Router\Interface;
use Closure;
/**
* -------------------------------------------------------------------------------
*
* HANDLE WEB ROUTINGS INTERFACE
*
* Create web routes that accept different methods and render to the client area
*
* @author Dave Conco <concodave@gmail.com>
* @link https://github.com/dconco/php_slides
* @category api, router, php router, php
* @copyright 2023 - 2024 Dave Conco
* @package PhpSlides
* @version ^1.0.0
* @return void
* |
*
* -------------------------------------------------------------------------------
*/
interface RouteInterface
{
/**
* ------------------------------------------------------------------------
*
* ANY REQUEST FROM ROUTE
*
* Accept all type of request or any other method
*
* Cannot evaluate `{?} URL parameters` in route if it's an array
* |
*
* @param array|string $route This describes the URL string to check if it matches the request URL, use array of URLs for multiple request
* @param mixed $callback Can contain any types of data to return to the client side/browser.
*
* ------------------------------------------------------------------------
*/
public static function any (
array|string $route,
mixed $callback,
string $method = '*',
): self;
/**
* MAP method
* Check out documentation for using Map method
*
* @link https://github.com/phpslides/phpslides
* @param string $method Can also be used as `$route` param if the `$route` param is not specified
* @param string|array $route Route parameter
*/
public static function map (string $method, string|array $route): self;
/**
* name METHOD
* Give a route a name for later use
*
* @param string $name
*/
public function name (string $name): self;
/**
* Action method
* In outputting information to the client area
*
* @param mixed $callback
*/
public function action (mixed $callback): self;
/**
* Controller method
* Work with map controller route
*
* @param string $controller
* @return void
*/
public function use(string $controller): self;
/**
* view method
* output view file directly
*
* @param string $file
*/
public function file (string $file): self;
/**
* Applies Authentication Guard to the current route.
*
* @param string ...$guards String parameters of registered guards.
* @return self
*/
public function withGuard (string ...$guards): self;
/**
* ---------------------------------------------------------------------------
*
* VIEW ROUTE METHOD
*
* Route only needs to return a view; you may provide an array for multiple request
*
* View Route does not accept `{?} URL parameters` in route, use GET method instead
*
* @param array|string $route This describes the URL string to render, use array of strings for multiple request
* @param string $view It renders this param, it can be functions to render, view:: to render or strings of text or documents
* |
*
* ---------------------------------------------------------------------------
*/
public static function view (array|string $route, string $view): self;
/**
* --------------------------------------------------------------
*
* REDIRECT ROUTE METHOD
*
* This method redirects the routes URL to the giving URL directly
*
* @param string $route The requested url to redirect
* @param string $new_url The new URL route to redirect to
* @param int $code The code for redirect method, 301 for permanent redirecting & 302 for temporarily redirect.
*
* ---------------------------------------------------------------
*/
public static function redirect (
string $route,
string $new_url,
int $code = 302,
): self;
/**
* --------------------------------------------------------------
*
* GET ROUTE METHOD
*
* Cannot evaluate {?} URL parameters in route if it's an array
*
* --------------------------------------------------------------
*/
public static function get (array|string $route, $callback): self;
/**
* --------------------------------------------------------------
*
* POST ROUTE METHOD
*
* Cannot evaluate {?} URL parameters in route if it's an array
*
* --------------------------------------------------------------
*/
public static function post (array|string $route, $callback): self;
/**
* --------------------------------------------------------------
*
* PUT ROUTE METHOD
*
* Cannot evaluate {?} URL parameters in route if it's an array
*
* --------------------------------------------------------------
*/
public static function put (array|string $route, $callback): self;
/**
* --------------------------------------------------------------
*
* PATCH ROUTE METHOD
*
* Cannot evaluate {?} URL parameters in route if it's an array
*
* --------------------------------------------------------------
*/
public static function patch (array|string $route, $callback): self;
/**
* --------------------------------------------------------------
*
* DELETE ROUTE METHOD
*
* Cannot evaluate {?} URL parameters in route if it's an array
*
* --------------------------------------------------------------
*/
public static function delete (array|string $route, $callback): self;
public function __destruct ();
}