1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Scrawler package. |
4
|
|
|
* |
5
|
|
|
* (c) Pranjal Pandey <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Scrawler\Traits; |
12
|
|
|
|
13
|
|
|
trait Router |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Register controller directory and namespace for autorouting. |
17
|
|
|
*/ |
18
|
|
|
public function registerAutoRoute(string $dir, string $namespace): void |
19
|
|
|
{ |
20
|
|
|
$this->router->register($dir, $namespace); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Register a new get route with the router. |
25
|
|
|
*/ |
26
|
|
|
public function get(string $route, \Closure|callable $callback): void |
27
|
|
|
{ |
28
|
|
|
$callback = \Closure::fromCallable(callback: $callback); |
29
|
|
|
$this->router->get($route, $callback); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Register a new post route with the router. |
34
|
|
|
*/ |
35
|
|
|
public function post(string $route, \Closure|callable $callback): void |
36
|
|
|
{ |
37
|
|
|
$callback = \Closure::fromCallable(callback: $callback); |
38
|
|
|
$this->router->post($route, $callback); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Register a new put route with the router. |
43
|
|
|
*/ |
44
|
|
|
public function put(string $route, \Closure|callable $callback): void |
45
|
|
|
{ |
46
|
|
|
$callback = \Closure::fromCallable(callback: $callback); |
47
|
|
|
$this->router->put($route, $callback); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Register a new delete route with the router. |
52
|
|
|
*/ |
53
|
|
|
public function delete(string $route, \Closure|callable $callback): void |
54
|
|
|
{ |
55
|
|
|
$callback = \Closure::fromCallable(callback: $callback); |
56
|
|
|
$this->router->delete($route, $callback); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Register a new all route with the router. |
61
|
|
|
*/ |
62
|
|
|
public function all(string $route, \Closure|callable $callback): void |
63
|
|
|
{ |
64
|
|
|
$callback = \Closure::fromCallable(callback: $callback); |
65
|
|
|
$this->router->all($route, $callback); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|