| Total Complexity | 4 |
| Total Lines | 41 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 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) |
||
| 42 | } |
||
| 43 | |||
| 44 | abstract public function getDefaultConfig():array; |
||
| 45 | } |
||
| 46 |