Php 如何构建基于类的RequestGuards?

Php 如何构建基于类的RequestGuards?,php,authentication,lumen,separation-of-concerns,Php,Authentication,Lumen,Separation Of Concerns,我正在尝试构建一个有效的回调来处理Lumen 5.2中的身份验证请求。然而,业务逻辑越来越混乱,这不是我喜欢的东西 是否有可能构建与viaRequest完全相同的东西,但是使用一个独立的类来处理请求 这是我的AuthServiceProvider.phpcode: 公共函数启动() { [...] $this->app['auth']->viaRequest('api',函数($request){ $typeOfLogins=['password','oauth']; 开关($request->

我正在尝试构建一个有效的回调来处理Lumen 5.2中的身份验证请求。然而,业务逻辑越来越混乱,这不是我喜欢的东西

是否有可能构建与
viaRequest
完全相同的东西,但是使用一个独立的类来处理请求

这是我的
AuthServiceProvider.php
code:

公共函数启动()
{
[...]
$this->app['auth']->viaRequest('api',函数($request){
$typeOfLogins=['password','oauth'];
开关($request->input('type'))
{
案例“密码”:
{
$user=authenticationuser::where([
'email'=>$request->input('email')
])->第一个();
if(!$user | |!$user->authenticable | |!($user->authenticable instanceof\Core\entications\user)){
返回null;
}
返回($this->app['hash']->check($request->input('password'),$user->authenticable->password))
?$user
:null;
}
案例“oauth”:
{
$user=authenticationuser::where([
'email'=>$request->input('email')
])->第一个();
如果(!$user){
返回null;
}
$provider=provider::where([
'user_id'=>$user->id,
“提供者”=>$request->input('provider'),
'provider\u user\u id'=>$request->input('user\u id'))
])->第一个();
$methodName=“verify”.ucfirst($request->input('provider'))“Token”;
$verification=$this->$methodName($request->input('token'),$request->input('user_id');
如果(!$verification){
返回null;
}
返回($provider)?$user:null;
}
}
});
}
受保护的函数verifyFacebookToken($token,$userId)
{
$facebook=app(\SammyK\LaravelFacebookSdk\LaravelFacebookSdk::class);
尝试
{
$response=$facebook->get('/me?fields=id,name',$token);
$graphUser=$response->getGraphUser();
返回$graphUser->getId()==$userId;
}捕获(\Facebook\Exceptions\FacebookResponseException$e){
返回false;
}
}