Skip to content

Commit d3c52bb

Browse files
committed
update
1 parent 877b03c commit d3c52bb

6 files changed

Lines changed: 49 additions & 69 deletions

File tree

example/test.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@
33
include __DIR__ . '/../vendor/autoload.php';
44
include __DIR__ . '/User.php';
55

6-
use think\User\Config;
76
use think\User\Auth;
8-
use think\User\Drive\Jwt;
97
use think\User\Drive\Session;
108
use 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

2223
var_dump($auth->isLogin());
23-
$auth->user();
24+
$auth->user();

src/Auth.php

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,69 @@
22

33
namespace think\User;
44

5+
use think\User\Config\Config;
56
use think\User\Drive\DriveManager;
6-
use think\User\Config;
77

88
class 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)

src/AuthService.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff 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
});

src/Config.php renamed to src/Config/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace think\User;
3+
namespace think\User\Config;
44

55
class Config
66
{

src/Drive/DriveManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace think\User\Drive;
44

55
use think\User\AuthorizationUserInterface;
6-
use think\User\Config;
6+
use think\User\Config\Config;
77
use think\User\Drive\DriveInterface;
88
use 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
}

src/Drive/Jwt.php

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)