mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 11:48:08 +08:00
Merge pull request #931 from qingpizi/master
Added strict_mode for config_apollo.
This commit is contained in:
commit
c3bf94f27e
@ -6,6 +6,7 @@
|
||||
- [#905](https://github.com/hyperf/hyperf/pull/905) Added twig template engine for view.
|
||||
- [#911](https://github.com/hyperf/hyperf/pull/911) Added support for crontab task run on one server.
|
||||
- [#913](https://github.com/hyperf/hyperf/pull/913) Added `Hyperf\ExceptionHandler\Listener\ErrorExceptionHandler`.
|
||||
- [#931](https://github.com/hyperf/hyperf/pull/931) Added `strict_mode` for config-apollo.
|
||||
|
||||
## Fixed
|
||||
|
||||
|
@ -19,4 +19,5 @@ return [
|
||||
'application',
|
||||
],
|
||||
'interval' => 5,
|
||||
'strict_mode' => false,
|
||||
];
|
||||
|
@ -83,10 +83,39 @@ class OnPipeMessageListener implements ListenerInterface
|
||||
return;
|
||||
}
|
||||
foreach ($data->configurations ?? [] as $key => $value) {
|
||||
$this->config->set($key, $value);
|
||||
$this->config->set($key, $this->formatValue($value));
|
||||
$this->logger->debug(sprintf('Config [%s] is updated', $key));
|
||||
}
|
||||
ReleaseKey::set($cacheKey, $data->releaseKey);
|
||||
}
|
||||
}
|
||||
|
||||
private function formatValue($value)
|
||||
{
|
||||
if (! $this->config->get('apollo.strict_mode', false)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
switch (strtolower($value)) {
|
||||
case 'true':
|
||||
case '(true)':
|
||||
return true;
|
||||
case 'false':
|
||||
case '(false)':
|
||||
return false;
|
||||
case 'empty':
|
||||
case '(empty)':
|
||||
return '';
|
||||
case 'null':
|
||||
case '(null)':
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_numeric($value)) {
|
||||
$value = (strpos($value, '.') === false) ? (int) $value : (float) $value;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user