Optimized code for config-nacos. (#6903)

This commit is contained in:
gaichao168 2024-06-24 11:04:35 +08:00 committed by GitHub
parent 298230f95a
commit e285377e67
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 15 deletions

View File

@ -4,6 +4,10 @@
- [#6900](https://github.com/hyperf/hyperf/pull/6900) Fixed bug that `LengthAwarePaginator::addQuery()` cannot support array `$values`.
## Optimized
- [#6903](https://github.com/hyperf/hyperf/pull/6903) Optimized code for `config-nacos`.
# v3.1.27 - 2024-06-20
## Added

View File

@ -48,8 +48,8 @@ class Client implements ClientInterface
$config = [];
foreach ($listener as $key => $item) {
$dataId = $item['data_id'];
$group = $item['group'];
$dataId = $item['data_id'] ?? '';
$group = $item['group'] ?? '';
$tenant = $item['tenant'] ?? null;
$type = $item['type'] ?? null;
$response = $this->client->config->get($dataId, $group, $tenant);
@ -66,17 +66,13 @@ class Client implements ClientInterface
public function decode(string $body, ?string $type = null): array|string
{
$type = strtolower((string) $type);
switch ($type) {
case 'json':
return Json::decode($body);
case 'yml':
case 'yaml':
return yaml_parse($body);
case 'xml':
return Xml::toArray($body);
default:
return $body;
}
return match ($type) {
'json' => Json::decode($body),
'yml', 'yaml' => yaml_parse($body),
'xml' => Xml::toArray($body),
default => $body,
};
}
public function getValidNodes(

View File

@ -45,8 +45,8 @@ class NacosDriver extends AbstractDriver
$application = $this->client->getClient();
$listeners = $this->config->get('config_center.drivers.nacos.listener_config', []);
foreach ($listeners as $key => $item) {
$dataId = $item['data_id'];
$group = $item['group'];
$dataId = $item['data_id'] ?? '';
$group = $item['group'] ?? '';
$tenant = $item['tenant'] ?? '';
$type = $item['type'] ?? null;