|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Uxmp\Core\Component\Config; |
|
6
|
|
|
|
|
7
|
|
|
use Configula\ConfigValues; |
|
8
|
|
|
use Psr\Log\LogLevel; |
|
9
|
|
|
|
|
10
|
|
|
final class ConfigProvider implements ConfigProviderInterface |
|
11
|
|
|
{ |
|
12
|
15 |
|
public function __construct( |
|
13
|
|
|
private readonly ConfigValues $configValues, |
|
14
|
|
|
) { |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
1 |
|
public function getLogFilePath(): string |
|
18
|
|
|
{ |
|
19
|
1 |
|
return $this->configValues->get('logging.path', ''); |
|
|
|
|
|
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
1 |
|
public function getJwtSecret(): string |
|
23
|
|
|
{ |
|
24
|
1 |
|
return $this->configValues->get('security.jwt_secret', ''); |
|
|
|
|
|
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
1 |
|
public function getCookieName(): string |
|
28
|
|
|
{ |
|
29
|
1 |
|
return $this->configValues->get('security.token_name', 'nekot'); |
|
|
|
|
|
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
1 |
|
public function getTokenLifetime(): int |
|
33
|
|
|
{ |
|
34
|
1 |
|
return (int) $this->configValues->get('security.token_lifetime', 1_086_400); |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
1 |
|
public function getLogLevel(): string |
|
38
|
|
|
{ |
|
39
|
1 |
|
return $this->configValues->get('logging.level', LogLevel::ERROR); |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
1 |
|
public function getCorsOrigin(): string |
|
43
|
|
|
{ |
|
44
|
1 |
|
return $this->configValues->get('http.cors_origin', ''); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
4 |
|
public function getApiBasePath(): string |
|
48
|
|
|
{ |
|
49
|
4 |
|
return $this->configValues->get('http.api_base_path', ''); |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
1 |
|
public function getAssetPath(): string |
|
53
|
|
|
{ |
|
54
|
1 |
|
return $this->configValues->get('assets.path', ''); |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
1 |
|
public function getDebugMode(): bool |
|
58
|
|
|
{ |
|
59
|
1 |
|
return (bool) $this->configValues->get('debug.enabled', false); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
1 |
|
public function getDatabaseDsn(): string |
|
63
|
|
|
{ |
|
64
|
1 |
|
return $this->configValues->get('database.dsn', ''); |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
1 |
|
public function getDatabasePassword(): string |
|
68
|
|
|
{ |
|
69
|
1 |
|
return $this->configValues->get('database.password', ''); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
3 |
|
public function getBaseUrl(): string |
|
73
|
|
|
{ |
|
74
|
3 |
|
$hostname = $this->configValues->get('http.hostname', ''); |
|
75
|
3 |
|
$port = (int) $this->configValues->get('http.port', 0); |
|
76
|
3 |
|
$ssl = ((bool) $this->configValues->get('http.ssl', true)) === true; |
|
77
|
|
|
|
|
78
|
3 |
|
$protocol = ($ssl === true) |
|
79
|
2 |
|
? 'https' |
|
80
|
1 |
|
: 'http'; |
|
81
|
|
|
|
|
82
|
3 |
|
$port_string = ''; |
|
83
|
|
|
if ( |
|
84
|
3 |
|
$port !== 0 && |
|
85
|
3 |
|
!in_array($port, [80, 443], true) |
|
86
|
|
|
) { |
|
87
|
1 |
|
$port_string = sprintf(':%d', $port); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
3 |
|
return sprintf( |
|
91
|
|
|
'%s://%s%s%s', |
|
92
|
|
|
$protocol, |
|
93
|
|
|
$hostname, |
|
|
|
|
|
|
94
|
|
|
$port_string, |
|
95
|
3 |
|
$this->getApiBasePath() |
|
96
|
|
|
); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
1 |
|
public function getClientCacheMaxAge(): int |
|
100
|
|
|
{ |
|
101
|
1 |
|
return 86400 * 100; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|