|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yansongda\Pay\Service; |
|
6
|
|
|
|
|
7
|
|
|
use Yansongda\Pay\Contract\ConfigInterface; |
|
8
|
|
|
use Yansongda\Pay\Contract\LoggerInterface; |
|
9
|
|
|
use Yansongda\Pay\Contract\ServiceProviderInterface; |
|
10
|
|
|
use Yansongda\Pay\Pay; |
|
11
|
|
|
use Yansongda\Supports\Logger; |
|
12
|
|
|
|
|
13
|
|
|
class LoggerServiceProvider implements ServiceProviderInterface |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @throws \Yansongda\Pay\Exception\ContainerDependencyException |
|
17
|
|
|
* @throws \Yansongda\Pay\Exception\ContainerException |
|
18
|
|
|
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException |
|
19
|
|
|
*/ |
|
20
|
|
|
public function register(Pay $pay, ?array $data = null): void |
|
21
|
|
|
{ |
|
22
|
|
|
/* @var ConfigInterface $config */ |
|
23
|
|
|
$config = Pay::get(ConfigInterface::class); |
|
24
|
|
|
|
|
25
|
|
|
$logger = new class() implements \Psr\Log\LoggerInterface { |
|
26
|
|
|
public function emergency($message, array $context = []): void |
|
27
|
|
|
{ |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function alert($message, array $context = []) |
|
31
|
|
|
{ |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function critical($message, array $context = []) |
|
35
|
|
|
{ |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function error($message, array $context = []) |
|
39
|
|
|
{ |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function warning($message, array $context = []) |
|
43
|
|
|
{ |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function notice($message, array $context = []) |
|
47
|
|
|
{ |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function info($message, array $context = []) |
|
51
|
|
|
{ |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function debug($message, array $context = []) |
|
55
|
|
|
{ |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function log($level, $message, array $context = []) |
|
59
|
|
|
{ |
|
60
|
|
|
} |
|
61
|
|
|
}; |
|
62
|
|
|
|
|
63
|
|
|
if (class_exists(\Monolog\Logger::class) && true === $config->get('logger.enable', false)) { |
|
64
|
|
|
$logger = new Logger(array_merge( |
|
65
|
|
|
['identify' => 'yansongda.pay'], $config->get('logger', []) |
|
66
|
|
|
)); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
Pay::set(LoggerInterface::class, $logger); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|