Passed
Push — master ( f2cf92...5bb09d )
by 世昌
01:42
created

AbstractLogger::interpolate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
namespace nebula\component\debug\log;
3
4
/**
5
 * 抽象日志记录工具
6
 */
7
abstract class AbstractLogger implements LoggerInterface
8
{
9
    public function emergency(string $message, array $context = [])
10
    {
11
        $this->log(LogLevel::EMERGENCY, $message, $context);
12
    }
13
   
14
    public function alert(string $message, array $context = [])
15
    {
16
        $this->log(LogLevel::ALERT, $message, $context);
17
    }
18
    
19
    public function critical(string $message, array $context = [])
20
    {
21
        $this->log(LogLevel::CRITICAL, $message, $context);
22
    }
23
   
24
    public function error(string $message, array $context = [])
25
    {
26
        $this->log(LogLevel::ERROR, $message, $context);
27
    }
28
29
    public function warning(string $message, array $context = [])
30
    {
31
        $this->log(LogLevel::WARNING, $message, $context);
32
    }
33
    
34
    public function notice(string $message, array $context = [])
35
    {
36
        $this->log(LogLevel::NOTICE, $message, $context);
37
    }
38
    
39
    public function info(string $message, array $context = [])
40
    {
41
        $this->log(LogLevel::INFO, $message, $context);
42
    }
43
    
44
    public function debug(string $message, array $context = [])
45
    {
46
        $this->log(LogLevel::DEBUG, $message, $context);
47
    }
48
    
49
    public function interpolate(string $message, array $context)
50
    {
51
        $replace = [];
52
        foreach ($context as $key => $val) {
53
            $replace['{' . $key . '}'] = $val;
54
        }
55
        return strtr($message, $replace);
56
    }
57
}
58