1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Conia\Chuck\Routing; |
6
|
|
|
|
7
|
|
|
use Conia\Chuck\Route; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @psalm-import-type View from \Conia\Chuck\Route |
11
|
|
|
*/ |
12
|
|
|
trait AddsRoutes |
13
|
|
|
{ |
14
|
|
|
abstract public function addRoute(Route $route): Route; |
15
|
|
|
|
16
|
|
|
/** @psalm-param View $view */ |
17
|
9 |
|
public function route(string $pattern, callable|array|string $view, string $name = ''): Route |
18
|
|
|
{ |
19
|
9 |
|
$route = new Route($pattern, $view, $name); |
20
|
9 |
|
$this->addRoute($route); |
21
|
|
|
|
22
|
9 |
|
return $route; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** @psalm-param View $view */ |
26
|
5 |
|
public function get(string $pattern, callable|array|string $view, string $name = ''): Route |
27
|
|
|
{ |
28
|
5 |
|
return $this->addRoute(Route::get($pattern, $view, $name)); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** @psalm-param View $view */ |
32
|
4 |
|
public function post(string $pattern, callable|array|string $view, string $name = ''): Route |
33
|
|
|
{ |
34
|
4 |
|
return $this->addRoute(Route::post($pattern, $view, $name)); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** @psalm-param View $view */ |
38
|
2 |
|
public function put(string $pattern, callable|array|string $view, string $name = ''): Route |
39
|
|
|
{ |
40
|
2 |
|
return $this->addRoute(Route::put($pattern, $view, $name)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** @psalm-param View $view */ |
44
|
2 |
|
public function patch(string $pattern, callable|array|string $view, string $name = ''): Route |
45
|
|
|
{ |
46
|
2 |
|
return $this->addRoute(Route::patch($pattern, $view, $name)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** @psalm-param View $view */ |
50
|
2 |
|
public function delete(string $pattern, callable|array|string $view, string $name = ''): Route |
51
|
|
|
{ |
52
|
2 |
|
return $this->addRoute(Route::delete($pattern, $view, $name)); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** @psalm-param View $view */ |
56
|
2 |
|
public function head(string $pattern, callable|array|string $view, string $name = ''): Route |
57
|
|
|
{ |
58
|
2 |
|
return $this->addRoute(Route::head($pattern, $view, $name)); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** @psalm-param View $view */ |
62
|
2 |
|
public function options(string $pattern, callable|array|string $view, string $name = ''): Route |
63
|
|
|
{ |
64
|
2 |
|
return $this->addRoute(Route::options($pattern, $view, $name)); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** @psalm-param class-string $controller */ |
68
|
4 |
|
public function endpoint(array|string $path, string $controller, string|array $args): Endpoint |
69
|
|
|
{ |
70
|
|
|
/** @var RouteAdder $this */ |
71
|
4 |
|
return new Endpoint($this, $path, $controller, $args); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|