<?php
namespace app\middleware;

use Webman\MiddlewareInterface;
use Webman\Http\Response;
use Webman\Http\Request;

class Login implements MiddlewareInterface
{
    public function process(Request $request, callable $handler) : Response
    {
        $route = $request->route->getPath();
        if(substr($route, 0, 6) != "/login"){
            $id=$request->cookie('id', 'blank');
            $key=$request->cookie('key', 'blank');
            if($id=='blank' || $key='blank'){
                return redirect('/login');
            }
        }
        // 请求继续向洋葱芯穿越
        return $handler($request);
    }
}