1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace hiapi\Core\Http; |
5
|
|
|
|
6
|
|
|
use hiapi\Core\Http\Psr15\Middleware\EndpointMiddleware; |
7
|
|
|
use Yiisoft\Router\Route; |
8
|
|
|
|
9
|
|
|
class EndpointRoute |
10
|
|
|
{ |
11
|
|
|
public static function get(string $pattern, string $name): Route |
12
|
|
|
{ |
13
|
|
|
return Route::get($pattern, static::buildMiddlewareFor($name)); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public static function post(string $pattern, string $name): Route |
17
|
|
|
{ |
18
|
|
|
return Route::post($pattern, static::buildMiddlewareFor($name)); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public static function put(string $pattern, string $name): Route |
22
|
|
|
{ |
23
|
|
|
return Route::put($pattern, static::buildMiddlewareFor($name)); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public static function delete(string $pattern, string $name): Route |
27
|
|
|
{ |
28
|
|
|
return Route::delete($pattern, static::buildMiddlewareFor($name)); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public static function patch(string $pattern, string $name): Route |
32
|
|
|
{ |
33
|
|
|
return Route::patch($pattern, static::buildMiddlewareFor($name)); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public static function head(string $pattern, string $name): Route |
37
|
|
|
{ |
38
|
|
|
return Route::head($pattern, static::buildMiddlewareFor($name)); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public static function options(string $pattern, string $name): Route |
42
|
|
|
{ |
43
|
|
|
return Route::options($pattern, static::buildMiddlewareFor($name)); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public static function anyMethod(string $pattern, string $name): Route |
47
|
|
|
{ |
48
|
|
|
return Route::anyMethod($pattern, static::buildMiddlewareFor($name)); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public static function buildMiddlewareFor(string $name): \Closure |
52
|
|
|
{ |
53
|
|
|
return EndpointMiddleware::for($name); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|