File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ composer require kriss/webman-auth
3535### 认证授权方法
3636
3737``` php
38- use Kriss\WebmanAuth\facade\ Auth;
38+ use Kriss\WebmanAuth\Auth;
3939
4040$guard = Auth::guard(); // 获取默认的 guard
4141$guard = Auth::guard('admin'); // 获取指定名称的 guard
Original file line number Diff line number Diff line change 33namespace app \admin \controller ;
44
55use app \model \Admin ;
6- use Kriss \WebmanAuth \facade \ Auth ;
6+ use Kriss \WebmanAuth \Auth ;
77use support \Request ;
88use support \Response ;
99
Original file line number Diff line number Diff line change 33namespace app \api \controller ;
44
55use app \model \User ;
6- use Kriss \WebmanAuth \facade \ Auth ;
6+ use Kriss \WebmanAuth \Auth ;
77use support \Request ;
88use support \Response ;
99
File renamed without changes.
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Kriss \WebmanAuth ;
4+
5+ use Kriss \WebmanAuth \Interfaces \GuardInterface ;
6+ use Kriss \WebmanAuth \Middleware \SetAuthGuard ;
7+
8+ class Auth
9+ {
10+ const REQUEST_AUTH_MANAGER = 'auth_manager ' ;
11+
12+ /**
13+ * guard
14+ * 当使用 Middleware/SetAuthGuard 后,可以获取到当前的 Guard
15+ * @param string|null $name
16+ * @return GuardInterface|null
17+ */
18+ public static function guard (string $ name = null ): ?GuardInterface
19+ {
20+ if ($ authManager = static ::getAuthManager ()) {
21+ $ name = $ name ?: request ()->{SetAuthGuard::REQUEST_GUARD_NAME };
22+ return $ authManager ->guard ($ name );
23+ }
24+ return null ;
25+ }
26+
27+ /**
28+ * @return AuthManager|null
29+ */
30+ public static function getAuthManager (): ?AuthManager
31+ {
32+ $ request = request ();
33+ if (!$ request ) {
34+ return null ;
35+ }
36+ if (!$ request ->{static ::REQUEST_AUTH_MANAGER }) {
37+ $ request ->{static ::REQUEST_AUTH_MANAGER } = new AuthManager ();
38+ }
39+ return $ request ->{static ::REQUEST_AUTH_MANAGER };
40+ }
41+ }
Original file line number Diff line number Diff line change 22
33namespace Kriss \WebmanAuth \Middleware ;
44
5- use Kriss \WebmanAuth \facade \ Auth ;
5+ use Kriss \WebmanAuth \Auth ;
66use Kriss \WebmanAuth \Interfaces \GuardInterface ;
77use Kriss \WebmanAuth \Interfaces \IdentityInterface ;
88use Webman \Http \Request ;
Original file line number Diff line number Diff line change 22
33namespace Kriss \WebmanAuth \facade ;
44
5- use Kriss \WebmanAuth \AuthManager ;
6- use Kriss \WebmanAuth \Interfaces \GuardInterface ;
7- use Kriss \WebmanAuth \Middleware \SetAuthGuard ;
8-
9- class Auth
5+ /**
6+ * @deprecated
7+ */
8+ class Auth extends \Kriss \WebmanAuth \Auth
109{
11- const REQUEST_AUTH_MANAGER = 'auth_manager ' ;
12-
13- /**
14- * guard
15- * 当使用 Middleware/SetAuthGuard 后,可以获取到当前的 Guard
16- * @param string|null $name
17- * @return GuardInterface|null
18- */
19- public static function guard (string $ name = null ): ?GuardInterface
20- {
21- if ($ authManager = static ::getAuthManager ()) {
22- $ name = $ name ?: request ()->{SetAuthGuard::REQUEST_GUARD_NAME };
23- return $ authManager ->guard ($ name );
24- }
25- return null ;
26- }
27-
28- /**
29- * @return AuthManager|null
30- */
31- public static function getAuthManager (): ?AuthManager
32- {
33- $ request = request ();
34- if (!$ request ) {
35- return null ;
36- }
37- if (!$ request ->{static ::REQUEST_AUTH_MANAGER }) {
38- $ request ->{static ::REQUEST_AUTH_MANAGER } = new AuthManager ();
39- }
40- return $ request ->{static ::REQUEST_AUTH_MANAGER };
41- }
4210}
You can’t perform that action at this time.
0 commit comments