优化 auth 单例获取用户,支持 guard 获取
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
1
extend/catcher/command/TestCommand.php
Normal file
1
extend/catcher/command/TestCommand.php
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<?php
|
1
extend/catcher/library/excel/Excel.php
Normal file
1
extend/catcher/library/excel/Excel.php
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<?php
|
14
extend/catcher/library/excel/ExcelContract.php
Normal file
14
extend/catcher/library/excel/ExcelContract.php
Normal 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;
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user