<?php


namespace App\Http\Middleware;

use Closure;
use App\Exceptions\ApiException;

class BindToken
{
    use CheckTokenTrait;

    /**
     * @param         $request
     * @param Closure $next
     * @return mixed
     * @throws ApiException
     */
    public function handle($request, Closure $next)
    {
        // 接口中的token(如有则绑定token到全局)
        $token     = $request->header('d-token', '');
        if ($token) {
            $this->checkTokenTrait($token);
        }
        return $next($request);
    }
}
