Last active
August 16, 2018 09:17
-
-
Save storyflow/a7290e03aeb3a1e5c578fa6ccd809758 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$db = function ($request, Closure $next) { | |
echo '成功建立数据库连接' . PHP_EOL; | |
$response = $next($request); | |
echo '成功关闭数据库连接' . PHP_EOL; | |
return $response; | |
}; | |
$like = function ($request, Closure $next) { | |
echo '点赞+1' . PHP_EOL; | |
$response = $next($request); | |
echo '点赞+2' . PHP_EOL; | |
return $response; | |
}; | |
$app = function ($request) { | |
echo $request . PHP_EOL; | |
return '一个无聊的返回值'; | |
}; | |
$allMiddleware = [$like, $db]; | |
$next = $app; | |
foreach ($allMiddleware as $middleware) { | |
$next = function ($request) use ($middleware, $next) { | |
return $middleware($request, $next); | |
}; | |
} | |
$response = $next('O(∩_∩)O'); | |
echo $response; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment