-
-
Notifications
You must be signed in to change notification settings - Fork 207
/
Services.php
91 lines (74 loc) · 2.29 KB
/
Services.php
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php namespace Myth\Auth\Config;
use CodeIgniter\Model;
use Myth\Auth\Authorization\FlatAuthorization;
use Myth\Auth\Models\UserModel;
use Myth\Auth\Models\LoginModel;
use Myth\Authorization\GroupModel;
use Myth\Authorization\PermissionModel;
use Myth\Auth\Authentication\Passwords\PasswordValidator;
use CodeIgniter\Config\BaseService;
class Services extends BaseService
{
public static function authentication(string $lib = 'local', Model $userModel=null, Model $loginModel=null, bool $getShared = true)
{
if ($getShared)
{
return self::getSharedInstance('authentication', $lib, $userModel, $loginModel);
}
$config = config(Auth::class);
$class = $config->authenticationLibs[$lib];
$instance = new $class($config);
if (empty($userModel))
{
$userModel = new UserModel();
}
if (empty($loginModel))
{
$loginModel = new LoginModel();
}
return $instance
->setUserModel($userModel)
->setLoginModel($loginModel);
}
public static function authorization(Model $groupModel=null, Model $permissionModel=null, Model $userModel=null, bool $getShared = true)
{
if ($getShared)
{
return self::getSharedInstance('authorization', $groupModel, $permissionModel);
}
if (is_null($groupModel))
{
$groupModel = new GroupModel();
}
if (is_null($permissionModel))
{
$permissionModel = new PermissionModel();
}
$instance = new FlatAuthorization($groupModel, $permissionModel);
if (is_null($userModel))
{
$userModel = new UserModel();
}
return $instance->setUserModel($userModel);
}
/**
* Returns an instance of the password validator.
*
* @param null $config
* @param bool $getShared
*
* @return mixed|PasswordValidator
*/
public static function passwords($config = null, bool $getShared = true)
{
if ($getShared)
{
return self::getSharedInstance('passwords', $config);
}
if (empty($config))
{
$config = config(Auth::class);
}
return new PasswordValidator($config);
}
}