Closed inspurhua closed 4 years ago
看了一下,你这个功能没实现完整啊?
看了一下,你这个功能没实现完整啊?
只加上了“类@方法”这种形式的路由参数,这个框架很好用,对于is_callable的,array形式的,我还不会处理。
好吧,你这是个方法级别的中间件处理
class IndexController
{
public $middleware = ['index' => [__CLASS__ . '::test']];
public static function test($handler)
{
return function ($request, $response, $vars) use ($handler) {
// do something
return $handler($request, $response, $vars);
};
}
public function index($request, $response)
{
$response->end(
json_encode(
[
'method' => $request->server['request_method'],
'message' => 'Hello Simps.'
]
)
);
}
}
function auth($handler){ return function($request, $response, $vars) use ($handler) { // do some buissiness logic return $handler($request, $response, $vars); }; }