Passed
Push — master ( 79eb06...102376 )
by 世昌
02:35
created

ConfigTrait::setConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
namespace suda\framework\debug;
3
4
trait ConfigTrait
5
{
6
    
7
    /**
8
     * 配置信息
9
     *
10
     * @var array
11
     */
12
    protected $config;
13
14
    /**
15
     * @param array $config
16
     */
17
    public function applyConfig(array $config)
18
    {
19
        $defaultConfig = $this->getDefaultConfig();
20
        foreach ($defaultConfig as $name => $value) {
21
            $this->config[$name] = $config[$name] ?? $this->config[$name] ?? $value;
22
        }
23
    }
24
25
    /**
26
     * @param string $name
27
     * @param $value
28
     */
29
    public function setConfig(string $name, $value)
30
    {
31
        $this->config[$name] = $value;
32
    }
33
34
    /**
35
     * @param string $name
36
     * @return mixed
37
     */
38
    public function getConfig(string $name)
39
    {
40
        $defaultConfig = $this->getDefaultConfig();
41
        return $this->config[$name] ?? $defaultConfig[$name];
42
    }
43
44
    abstract public function getDefaultConfig():array;
45
}
46