1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Garbuzivan\Laraveltokens; |
6
|
|
|
|
7
|
|
|
use Garbuzivan\Laraveltokens\Repositories\AccessTokenRepository; |
8
|
|
|
use Garbuzivan\Laraveltokens\Repositories\GlobalTokenRepository; |
9
|
|
|
|
10
|
|
|
class Config |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Соль для сигнатур |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected string $salt = 'Fo3SMqqUbrxKJMQW0sVOB4Q'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Название конфигурационного файла |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected string $configName = 'laraveltokens'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Хранение в токена в открытом или зашифрованном виде |
28
|
|
|
* Зашифрованный тип хранения отключает возможность просматривать токен или вносить его вручную |
29
|
|
|
* |
30
|
|
|
* @var bool |
31
|
|
|
*/ |
32
|
|
|
protected bool $encryption = false; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Автоматическое удаление токенов с законченым сроком действия |
36
|
|
|
* |
37
|
|
|
* @var bool |
38
|
|
|
*/ |
39
|
|
|
protected bool $autoClear = true; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Пауза перед автоматическим удалением токенов в секундах |
43
|
|
|
* |
44
|
|
|
* @var int |
45
|
|
|
*/ |
46
|
|
|
protected int $autoClearPause = 8640000; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Репозиторий |
50
|
|
|
* |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
protected string $repository_access = AccessTokenRepository::class; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Репозиторий |
57
|
|
|
* |
58
|
|
|
* @var string |
59
|
|
|
*/ |
60
|
|
|
protected string $repository_global = GlobalTokenRepository::class; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Фиксация последней активности токена |
64
|
|
|
* |
65
|
|
|
* @var bool |
66
|
|
|
*/ |
67
|
|
|
protected bool $lastUse = true; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Режим JWT |
71
|
|
|
* |
72
|
|
|
* @var bool |
73
|
|
|
*/ |
74
|
|
|
protected bool $jwt = true; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Configuration constructor. |
78
|
|
|
*/ |
79
|
|
|
public function __construct() |
80
|
|
|
{ |
81
|
|
|
$this->load(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Загрузка данных из конфигурационного файла |
86
|
|
|
* |
87
|
|
|
* @return $this|Config |
88
|
|
|
*/ |
89
|
|
|
public function load(): Config |
90
|
|
|
{ |
91
|
|
|
$this->encryption = (bool)config($this->configName . '.encryption', $this->encryption); |
92
|
|
|
$this->autoClear = (bool)config($this->configName . '.auto_clear', $this->autoClear); |
93
|
|
|
$this->autoClearPause = intval(config($this->configName . '.auto_clear_pause', $this->autoClearPause)); |
94
|
|
|
$this->repository_global = (string)config($this->configName . '.repository_global', $this->repository_global); |
95
|
|
|
$this->repository_access = (string)config($this->configName . '.repository_global', $this->repository_access); |
96
|
|
|
$this->lastUse = (bool)config($this->configName . '.last_use', $this->lastUse); |
97
|
|
|
$this->jwt = (bool)config($this->configName . '.jwt', $this->jwt); |
98
|
|
|
$this->salt = (string)config($this->configName . '.salt', $this->salt); |
99
|
|
|
$this->salt = file_exists($this->salt) ? file_get_contents($this->salt) : $this->salt; |
100
|
|
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Проверка на шифрование токена |
105
|
|
|
* |
106
|
|
|
* @return bool |
107
|
|
|
*/ |
108
|
|
|
public function isEncryption(): bool |
109
|
|
|
{ |
110
|
|
|
return $this->encryption; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Проверка на автоочистку от неиспользуемых токенов |
115
|
|
|
* |
116
|
|
|
* @return bool |
117
|
|
|
*/ |
118
|
|
|
public function isAutoClear(): bool |
119
|
|
|
{ |
120
|
|
|
return $this->autoClear; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Проверка на автоочистку от неиспользуемых токенов |
125
|
|
|
* |
126
|
|
|
* @return int |
127
|
|
|
*/ |
128
|
|
|
public function getAutoClearPause(): int |
129
|
|
|
{ |
130
|
|
|
return $this->autoClearPause; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Репозиторий Access |
135
|
|
|
* |
136
|
|
|
* @return string |
137
|
|
|
*/ |
138
|
|
|
public function getRepositoryAccessToken(): string |
139
|
|
|
{ |
140
|
|
|
return $this->repository_access; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Репозиторий Access |
145
|
|
|
* |
146
|
|
|
* @return string |
147
|
|
|
*/ |
148
|
|
|
public function getRepositoryGlobalToken(): string |
149
|
|
|
{ |
150
|
|
|
return $this->repository_global; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Обновлять последнюю активность токена Да\Нет |
155
|
|
|
* |
156
|
|
|
* @return bool |
157
|
|
|
*/ |
158
|
|
|
public function isLastUse(): bool |
159
|
|
|
{ |
160
|
|
|
return $this->lastUse; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Режим JWT |
165
|
|
|
* |
166
|
|
|
* @return bool |
167
|
|
|
*/ |
168
|
|
|
public function isJwt(): bool |
169
|
|
|
{ |
170
|
|
|
return $this->jwt; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Режим JWT |
175
|
|
|
* |
176
|
|
|
* @return string |
177
|
|
|
*/ |
178
|
|
|
public function getSalt(): string |
179
|
|
|
{ |
180
|
|
|
return $this->salt; |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|