1 | <?php |
||
8 | abstract class Handler |
||
9 | { |
||
10 | const SUCCESS = 'success'; |
||
11 | const FAILED = 'failed'; |
||
12 | |||
13 | /** |
||
14 | * @var |
||
15 | * @author kaylv <[email protected]> |
||
16 | */ |
||
17 | protected $app; |
||
18 | |||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $message; |
||
23 | |||
24 | /** |
||
25 | * @var string|null |
||
26 | */ |
||
27 | protected $fail; |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $attributes = []; |
||
33 | |||
34 | /** |
||
35 | * Check sign. |
||
36 | * If failed, throws an exception. |
||
37 | * |
||
38 | * @var bool |
||
39 | */ |
||
40 | protected $check = true; |
||
41 | |||
42 | /** |
||
43 | * Respond with sign. |
||
44 | * |
||
45 | * @var bool |
||
46 | */ |
||
47 | protected $sign = true; |
||
48 | |||
49 | /** |
||
50 | * Handler constructor. |
||
51 | * @param $app |
||
52 | */ |
||
53 | public function __construct($app) |
||
57 | |||
58 | /** |
||
59 | * 处理验签入口 |
||
60 | * @param Closure $closure |
||
61 | * @author kaylv <[email protected]> |
||
62 | * @return string |
||
63 | */ |
||
64 | abstract public function handle(Closure $closure); |
||
65 | |||
66 | /** |
||
67 | * @param string $message |
||
68 | */ |
||
69 | public function fail(string $message) |
||
73 | |||
74 | /** |
||
75 | * 响应数据 |
||
76 | * @author kaylv <[email protected]> |
||
77 | * @return string |
||
78 | */ |
||
79 | public function toResponse() |
||
83 | |||
84 | /** |
||
85 | * 获取参数并验签 |
||
86 | * @author kaylv <[email protected]> |
||
87 | * @return array |
||
88 | * @throws Exception |
||
89 | */ |
||
90 | public function getMessage(): array |
||
109 | |||
110 | /** |
||
111 | * 验签 |
||
112 | * @param $message |
||
113 | * @author kaylv <[email protected]> |
||
114 | * @throws Exception |
||
115 | */ |
||
116 | protected function validate($message) |
||
120 | |||
121 | /** |
||
122 | * 处理入口 |
||
123 | * @param mixed $result |
||
124 | */ |
||
125 | protected function strict($result) |
||
131 | |||
132 | /** |
||
133 | * 获取参数 |
||
134 | * @author kaylv <[email protected]> |
||
135 | * @return array |
||
136 | */ |
||
137 | protected function getInput() |
||
144 | } |
||
145 |