-
Notifications
You must be signed in to change notification settings - Fork 1
/
createsUserProviders.js
56 lines (45 loc) · 1.79 KB
/
createsUserProviders.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const InvalidArgumentException = require('@ostro/support/exceptions/invalidArgumentException')
const DatabaseUserProvider = require('./databaseUserProvider')
const EloquentUserProvider = require('./eloquentUserProvider')
class CreatesUserProviders {
$customProviderCreators = {};
createUserProvider($provider = null) {
let $config = this.getProviderConfiguration($provider)
if (is_null($config)) {
return;
}
let $driver = ($config['driver'] || null)
if (isset(this.$customProviderCreators[$driver])) {
return call_user_func(
this.$customProviderCreators[$driver], this.$container, $config
);
}
switch ($driver) {
case 'database':
return this.createDatabaseProvider($config);
case 'eloquent':
return this.createEloquentProvider($config);
default:
throw new InvalidArgumentException(
`Authentication user provider [{$driver}] is not defined.`
);
}
}
getProviderConfiguration(provider) {
provider = provider || this.getDefaultUserProvider()
if (provider) {
return this.$container.config.get(`auth.providers.${provider}`);
}
}
createDatabaseProvider($config) {
let $connection = this.$container['db'].connection($config['connection'] || null);
return new DatabaseUserProvider($connection, this.$container['hash'], $config['table']);
}
createEloquentProvider($config) {
return new EloquentUserProvider(this.$container['hash'], $config['model']);
}
getDefaultUserProvider() {
return this.$container.config.get('auth.defaults.provider');
}
}
module.exports = CreatesUserProviders