|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Micro framework package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Stanislau Komar <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Micro\Plugin\Http; |
|
15
|
|
|
|
|
16
|
|
|
use Micro\Framework\Kernel\Configuration\PluginConfiguration; |
|
17
|
|
|
use Micro\Plugin\Logger\LoggerPluginConfiguration; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @author Stanislau Komar <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class HttpLoggerPluginConfiguration extends PluginConfiguration implements HttpLoggerPluginConfigurationInterface |
|
23
|
|
|
{ |
|
24
|
|
|
public const CFG_LOGGER_ACCESS = 'MICRO_HTTP_LOGGER_ACCESS'; |
|
25
|
|
|
public const CFG_LOGGER_ERROR = 'MICRO_HTTP_LOGGER_ERROR'; |
|
26
|
|
|
public const CFG_LOGGER_HEADERS_SECURED = 'MICRO_HTTP_LOGGER_HEADERS_SECURED'; |
|
27
|
|
|
public const CFG_LOGGER_HEADERS_SECURED_DEFAULT = 'Authorization'; |
|
28
|
|
|
public const CFG_DECORATION_WEIGHT = 'MICRO_HTTP_LOGGER_DECORATION_WEIGHT'; |
|
29
|
|
|
public const CFG_HTTP_LOGGER_ACCESS_FORMAT = 'MICRO_HTTP_LOGGER_ACCESS_FORMAT'; |
|
30
|
|
|
public const CFG_HTTP_LOGGER_ERROR_FORMAT = 'MICRO_HTTP_LOGGER_ERROR_FORMAT'; |
|
31
|
|
|
public const LOGGER_ERROR_FORMAT_DEFAULT = '{{remote_addr}} - {{remote_user}} [{{status}}] "{{request}}"'; |
|
32
|
|
|
public const LOGGER_ACCESS_FORMAT_DEFAULT = '{{remote_addr}} - {{remote_user}} [{{status}}] "{{request}}" {{request_header.http-referer}} {{request_header.user-agent}}'; |
|
33
|
|
|
public const DECORATION_DEFAULT = 1000; |
|
34
|
|
|
|
|
35
|
1 |
|
public function getAccessLoggerName(): string |
|
36
|
|
|
{ |
|
37
|
1 |
|
return (string) $this->configuration->get(self::CFG_LOGGER_ACCESS, LoggerPluginConfiguration::LOGGER_NAME_DEFAULT); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
1 |
|
public function getErrorLoggerName(): string |
|
41
|
|
|
{ |
|
42
|
1 |
|
return (string) $this->configuration->get(self::CFG_LOGGER_ERROR, LoggerPluginConfiguration::LOGGER_NAME_DEFAULT); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
2 |
|
public function getWeight(): int |
|
46
|
|
|
{ |
|
47
|
2 |
|
return (int) $this->configuration->get(self::CFG_DECORATION_WEIGHT, self::DECORATION_DEFAULT, false); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
1 |
|
public function getErrorLogFormat(): string |
|
51
|
|
|
{ |
|
52
|
1 |
|
return $this->configuration->get(self::CFG_HTTP_LOGGER_ERROR_FORMAT, self::LOGGER_ERROR_FORMAT_DEFAULT, false); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
1 |
|
public function getAccessLogFormat(): string |
|
56
|
|
|
{ |
|
57
|
1 |
|
return $this->configuration->get(self::CFG_HTTP_LOGGER_ACCESS_FORMAT, self::LOGGER_ACCESS_FORMAT_DEFAULT, false); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
1 |
|
public function getRequestHeadersSecuredList(): array |
|
61
|
|
|
{ |
|
62
|
1 |
|
return $this->explodeStringToArray( |
|
63
|
1 |
|
$this->configuration->get( |
|
64
|
1 |
|
self::CFG_LOGGER_HEADERS_SECURED, |
|
65
|
1 |
|
self::CFG_LOGGER_HEADERS_SECURED_DEFAULT |
|
66
|
1 |
|
) |
|
67
|
1 |
|
); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|