优化 auth 单例获取用户,支持 guard 获取

This commit is contained in:
JaguarJack
2020-05-23 14:04:23 +08:00
parent fa04341608
commit 8bf7380d82
4 changed files with 26 additions and 6 deletions

View File

@@ -18,7 +18,7 @@ class CatchAuth
protected $password = 'password'; protected $password = 'password';
// 保存用户信息 // 保存用户信息
protected $user = null; protected $user = [];
public function __construct() public function __construct()
{ {
@@ -69,23 +69,27 @@ class CatchAuth
*/ */
public function user() public function user()
{ {
if (!$this->user) { $user = $this->user[$this->guard] ?? null;
if (!$user) {
switch ($this->getDriver()) { switch ($this->getDriver()) {
case 'jwt': case 'jwt':
$model = app($this->getProvider()['model']); $model = app($this->getProvider()['model']);
$this->user = $model->where($model->getPk(), JWTAuth::auth()[$this->jwtKey()])->find(); $user = $model->where($model->getPk(), JWTAuth::auth()[$this->jwtKey()])->find();
break; break;
case 'session': case 'session':
$this->user = Session::get($this->sessionUserKey(), null); $user = Session::get($this->sessionUserKey(), null);
break; break;
default: default:
throw new FailedException('user not found'); throw new FailedException('user not found');
} }
return $this->user; $this->user[$this->guard] = $user;
return $user;
} }
return $this->user; return $user;
} }
/** /**

View File

@@ -0,0 +1 @@
<?php

View File

@@ -0,0 +1 @@
<?php

View File

@@ -0,0 +1,14 @@
<?php
namespace catcher\library\excel;
interface Excel
{
public function title(): string;
public function headers(): array;
public function sheets(): array;
public function filename():string;
}