laravel - 这个表达式(终止)用于什么目的?
问题描述
我的终止中间件如下:
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Log;
class ExampleMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next, $role)
{
if ($role == null) {
return redirect('/deneme');
}
return $next($request);
}
public function terminate($request, $response)
{
sleep(4);//what is the purpose in this section(What this means is that anyone who has used this way?)
}
}
终止函数的目的是什么,它是什么以及何时应该使用它?
解决方案
有时,在准备好 HTTP 响应之后,中间件可能需要做一些工作。例如,Laravel 中包含的“会话”中间件在响应完全准备好后将会话数据写入存储。如果您在中间件上定义了终止方法,它将在响应准备好发送到浏览器后自动调用。
推荐阅读
- ruby - 如何在 Ruby Sinatra 中读取 GZIP 有效负载
- python - Python 在新实例中缓存以前的对象属性
- javascript - 如何在Javascript中获取相对于页面而不是相对于屏幕的鼠标坐标?
- ios - Healthkit 权限的自动单元测试
- python - 如何从文件中的 CIDR 生成所有 IP?
- python - 过滤日期行的参数化方式
- python - 模块“tensorflow._api.v1.metrics”没有属性“平均值”
- python - 一种删除字符串中括号内所有单词出现的方法?
- node.js - PayPal 发送多个相同的 webhook(节点)
- swift - “如何修复'链接器命令失败,退出代码为 1(使用 -v 查看调用)'?”