laravel-learn-bbs/app/Http/Kernel.php

87 lines
3.5 KiB
PHP
Raw Normal View History

2017-12-24 14:17:18 +00:00
<?php
namespace App\Http;
2018-06-16 01:15:01 +00:00
use App\Http\Middleware\ChangeLocale;
use App\Http\Middleware\RecordLastActivedTime;
2017-12-24 14:17:18 +00:00
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
* 全局中间件,最先调用
2017-12-24 14:17:18 +00:00
*
* @var array
*/
protected $middleware = [
// 检测是否应用是否进入『维护模式』
2017-12-24 14:17:18 +00:00
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
// 检测请求的数据是否过大
2017-12-24 14:17:18 +00:00
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
// 对提交的请求参数进行 PHP 函数 `trim()` 处理
2017-12-24 14:17:18 +00:00
\App\Http\Middleware\TrimStrings::class,
// 将提交请求参数中空子串转换为 null
2017-12-24 14:17:18 +00:00
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
// 修正代理服务器后的服务器参数
2017-12-24 14:17:18 +00:00
\App\Http\Middleware\TrustProxies::class,
];
/**
* The application's route middleware groups.
*定义中间件组
2017-12-24 14:17:18 +00:00
* @var array
*/
protected $middlewareGroups = [
// Web 中间件组,应用于 routes/web.php 路由文件
2017-12-24 14:17:18 +00:00
'web' => [
// Cookie 加密解密
2017-12-24 14:17:18 +00:00
\App\Http\Middleware\EncryptCookies::class,
// 将 Cookie 添加到响应中
2017-12-24 14:17:18 +00:00
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
// 开启会话
2017-12-24 14:17:18 +00:00
\Illuminate\Session\Middleware\StartSession::class,
// 认证用户,此中间件以后 Auth 类才能生效
2017-12-24 14:17:18 +00:00
// \Illuminate\Session\Middleware\AuthenticateSession::class,
// 将系统的错误数据注入到视图变量 $errors 中
2017-12-24 14:17:18 +00:00
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
// 检验 CSRF ,防止跨站请求伪造的安全威胁
2017-12-24 14:17:18 +00:00
\App\Http\Middleware\VerifyCsrfToken::class,
// 处理路由绑定
2017-12-24 14:17:18 +00:00
\Illuminate\Routing\Middleware\SubstituteBindings::class,
RecordLastActivedTime::class,
2017-12-24 14:17:18 +00:00
],
// API 中间件组,应用于 routes/api.php 路由文件
2017-12-24 14:17:18 +00:00
'api' => [
// 使用别名来调用中间件
2017-12-24 14:17:18 +00:00
'throttle:60,1',
'bindings',
],
];
/**
* The application's route middleware.
* 中间件别名设置,允许你使用别名调用中间件,例如上面的 api 中间件组调用
2017-12-24 14:17:18 +00:00
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
//只有登录用户才能访问,我们在控制器的构造方法中大量使用
2017-12-24 14:17:18 +00:00
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
// 处理路由绑定
2017-12-24 14:17:18 +00:00
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
// 用户授权功能
2017-12-24 14:17:18 +00:00
'can' => \Illuminate\Auth\Middleware\Authorize::class,
// 只有游客才能访问,在 register 和 login 请求中使用,只有未登录用户才能访问这些页面
2017-12-24 14:17:18 +00:00
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
// 访问节流,类似于 『1 分钟只能请求 10 次』的需求,一般在 API 中使用
2017-12-24 14:17:18 +00:00
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
2018-06-16 01:15:01 +00:00
//语言设置
'change-locale' => ChangeLocale::class,
2017-12-24 14:17:18 +00:00
];
}