Merge pull request #931 from qingpizi/master

Added strict_mode for config_apollo.
This commit is contained in:
李铭昕 2019-11-13 10:02:19 +08:00 committed by GitHub
commit c3bf94f27e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 1 deletions

View File

@ -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

View File

@ -19,4 +19,5 @@ return [
'application',
],
'interval' => 5,
'strict_mode' => false,
];

View File

@ -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;
}
}