-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSetAuthGuard.php
More file actions
38 lines (31 loc) · 898 Bytes
/
SetAuthGuard.php
File metadata and controls
38 lines (31 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace WebmanTech\Auth\Middleware;
use WebmanTech\CommonUtils\Middleware\BaseMiddleware;
use WebmanTech\CommonUtils\Request;
use WebmanTech\CommonUtils\Response;
/**
* 设置路由下的当前 auth 的 guardName
*/
class SetAuthGuard extends BaseMiddleware
{
public const REQUEST_GUARD_NAME = 'auth_current_guard_name';
public function __construct(protected ?string $guardName = null)
{
}
public static function setGuardName(Request $request, ?string $guardName = null): void
{
if ($guardName) {
$request->withCustomData([
static::REQUEST_GUARD_NAME => $guardName
]);
}
}
/**
* @inheritDoc
*/
public function processRequest(Request $request, \Closure $handler): Response
{
static::setGuardName($request, $this->guardName);
return $handler($request);
}
}