File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33include __DIR__ . '/../vendor/autoload.php ' ;
44include __DIR__ . '/User.php ' ;
55
6- use think \User \Config ;
76use think \User \Auth ;
8- use think \User \Drive \Jwt ;
97use think \User \Drive \Session ;
108use think \User \Drive \Cookie ;
119
1210$ options = [
13- 'drive ' => Session::class,
14- 'key ' => 'uid ' ,
15- 'model ' => User::class
11+ 'default ' => 'api ' ,
12+ 'stores ' => [
13+ 'api ' => [
14+ 'drive ' => Session::class,
15+ 'key ' => 'uid ' ,
16+ 'model ' => User::class
17+ ]
18+ ]
1619];
1720
18- $ config = new Config ($ options );
19-
2021$ auth = new Auth ($ config );
2122
2223var_dump ($ auth ->isLogin ());
23- $ auth ->user ();
24+ $ auth ->user ();
Original file line number Diff line number Diff line change 22
33namespace think \User ;
44
5+ use think \User \Config \Config ;
56use think \User \Drive \DriveManager ;
6- use think \User \Config ;
77
88class Auth
99{
10+ /**
11+ * @var array
12+ */
13+ protected $ options ;
14+
1015 /**
1116 * @var Config
1217 */
1318 protected $ config ;
1419
20+ /**
21+ * @var string
22+ */
23+ protected $ store ;
24+
1525 /**
1626 * @var DriveManager
1727 */
1828 protected $ manager ;
1929
20- public function __construct (Config $ config )
30+ public function __construct (array $ options )
2131 {
22- $ this ->config = $ config ;
32+ $ this ->options = $ options ;
2333
2434 $ this ->init ();
2535 }
2636
27- protected function init ()
37+ private function init ()
38+ {
39+ $ this ->makeConfig ();
40+ $ this ->makeManager ();
41+ }
42+
43+ public function store ($ store )
44+ {
45+ $ this ->store = $ store ;
46+ return $ this ;
47+ }
48+
49+ protected function getDefaultApp ()
50+ {
51+ return $ this ->options ['default ' ];
52+ }
53+
54+ protected function makeConfig ()
2855 {
29- $ this ->manager = $ this ->getManager ();
56+ $ app = $ this ->store ?? $ this ->getDefaultApp ();
57+ $ this ->config = new Config ($ this ->options ['stores ' ][$ app ]);
3058 }
3159
3260 protected function getConfig ()
3361 {
3462 return $ this ->config ;
3563 }
3664
37- protected function getManager ()
65+ protected function makeManager ()
3866 {
39- return new DriveManager ($ this ->config );
67+ $ this -> manager = new DriveManager ($ this ->config );
4068 }
4169
4270 public function __call ($ name , $ argv )
Original file line number Diff line number Diff line change @@ -8,9 +8,8 @@ class AuthService extends Service
88{
99 public function register ()
1010 {
11- $ this ->app ->bind ('auth ' , function () {
12- $ config = new Config (config ('auth ' ));
13- $ auth = new Auth ($ config );
11+ $ this ->app ->bind ('auth ' , function ($ store = null ) {
12+ $ auth = new Auth (config ('auth ' ));
1413
1514 return $ auth ;
1615 });
Original file line number Diff line number Diff line change 11<?php
22
3- namespace think \User ;
3+ namespace think \User \ Config ;
44
55class Config
66{
Original file line number Diff line number Diff line change 33namespace think \User \Drive ;
44
55use think \User \AuthorizationUserInterface ;
6- use think \User \Config ;
6+ use think \User \Config \ Config ;
77use think \User \Drive \DriveInterface ;
88use think \User \Exception \Unauthorized ;
99
@@ -52,7 +52,7 @@ protected function makeUser()
5252
5353 $ model = new $ class ();
5454 if ($ model instanceof AuthorizationUserInterface) {
55- return $ model ->find ($ id );
55+ return $ model ->getUserById ($ id );
5656 } else {
5757 throw new Unauthorized ('implements ' . AuthorizationUserInterface::class);
5858 }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments