|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Router\Handler; |
|
6
|
|
|
|
|
7
|
|
|
use Psr\Http\Server\MiddlewareInterface; |
|
8
|
|
|
|
|
9
|
|
|
use function array_unshift; |
|
10
|
|
|
|
|
11
|
|
|
trait HandlerAwareTrait |
|
12
|
|
|
{ |
|
13
|
|
|
private array $handlers = []; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Add handler that should be invoked for the route when match happens to the stack. |
|
17
|
|
|
* |
|
18
|
|
|
* @param mixed $handler that will be added. |
|
19
|
|
|
* Handler type and format support depends on the \Yiisoft\Router\Dispatcher\DispatcherInterface implementation. |
|
20
|
|
|
* @param bool $validate whether to validate handler before execution |
|
21
|
|
|
* |
|
22
|
|
|
* @return HandlerAwareInterface |
|
23
|
|
|
*/ |
|
24
|
|
|
public function handler($handler, $validate = false): HandlerAwareInterface |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
$this->handlers[] = $handler; |
|
27
|
|
|
|
|
28
|
|
|
return $this; |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Add multiple handlers that should be invoked for the route when match happens to the stack. |
|
33
|
|
|
* |
|
34
|
|
|
* @param array $handlers that will be added. |
|
35
|
|
|
* Handler type and format support depends on the \Yiisoft\Router\Dispatcher\DispatcherInterface implementation. |
|
36
|
|
|
* @param false $validate whether to validate handlers before execution |
|
37
|
|
|
* |
|
38
|
|
|
* @return HandlerAwareInterface |
|
39
|
|
|
*/ |
|
40
|
|
|
public function handlers(iterable $handlers, $validate = false): HandlerAwareInterface |
|
41
|
|
|
{ |
|
42
|
|
|
foreach ($handlers as $handler) { |
|
43
|
|
|
$this->handler($handler, $validate); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
return $this; |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Prepend handler that should be invoked for the route when match happens to the stack. |
|
51
|
|
|
* |
|
52
|
|
|
* @param mixed $handler that will be added. |
|
53
|
|
|
* Handler type and format support depends on the \Yiisoft\Router\Dispatcher\DispatcherInterface implementation. |
|
54
|
|
|
* @param bool $validate whether to validate handler before execution |
|
55
|
|
|
* |
|
56
|
|
|
* @return HandlerAwareInterface |
|
57
|
|
|
*/ |
|
58
|
|
|
public function prependHandler($handler, $validate = false): HandlerAwareInterface |
|
|
|
|
|
|
59
|
|
|
{ |
|
60
|
|
|
array_unshift($this->handlers, $handler); |
|
61
|
|
|
|
|
62
|
|
|
return $this; |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Get the stack of handlers that should be invoked for the route when match happens. |
|
67
|
|
|
* |
|
68
|
|
|
* @return iterable stack of handlers. |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getHandlers(): iterable |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->handlers; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.