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