mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-05 13:18:22 +08:00
Upgrade the minimum php version to 8.0 for config and config-center.
This commit is contained in:
parent
42b713eaa4
commit
c878ddb1c5
@ -16,7 +16,7 @@ use Psr\Container\ContainerInterface;
|
|||||||
|
|
||||||
class AliyunAcmDriver extends AbstractDriver
|
class AliyunAcmDriver extends AbstractDriver
|
||||||
{
|
{
|
||||||
protected $driverName = 'aliyun_acm';
|
protected string $driverName = 'aliyun_acm';
|
||||||
|
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
|
@ -17,34 +17,18 @@ use Hyperf\Contract\StdoutLoggerInterface;
|
|||||||
use Hyperf\Guzzle\ClientFactory as GuzzleClientFactory;
|
use Hyperf\Guzzle\ClientFactory as GuzzleClientFactory;
|
||||||
use Hyperf\Utils\Codec\Json;
|
use Hyperf\Utils\Codec\Json;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
|
||||||
class Client implements ClientInterface
|
class Client implements ClientInterface
|
||||||
{
|
{
|
||||||
/**
|
private GuzzleHttp\Client $client;
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public $fetchConfig;
|
|
||||||
|
|
||||||
/**
|
private ConfigInterface $config;
|
||||||
* @var null|GuzzleHttp\Client
|
|
||||||
*/
|
|
||||||
private $client;
|
|
||||||
|
|
||||||
/**
|
private LoggerInterface $logger;
|
||||||
* @var ConfigInterface
|
|
||||||
*/
|
|
||||||
private $config;
|
|
||||||
|
|
||||||
/**
|
private array $servers;
|
||||||
* @var \Psr\Log\LoggerInterface
|
|
||||||
*/
|
|
||||||
private $logger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $servers;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array[]
|
* @var array[]
|
||||||
@ -61,11 +45,6 @@ class Client implements ClientInterface
|
|||||||
|
|
||||||
public function pull(): array
|
public function pull(): array
|
||||||
{
|
{
|
||||||
$client = $this->client;
|
|
||||||
if (! $client instanceof GuzzleHttp\Client) {
|
|
||||||
throw new RuntimeException('aliyun acm: Invalid http client.');
|
|
||||||
}
|
|
||||||
|
|
||||||
// ACM config
|
// ACM config
|
||||||
$endpoint = $this->config->get('config_center.drivers.aliyun_acm.endpoint', 'acm.aliyun.com');
|
$endpoint = $this->config->get('config_center.drivers.aliyun_acm.endpoint', 'acm.aliyun.com');
|
||||||
$namespace = $this->config->get('config_center.drivers.aliyun_acm.namespace', '');
|
$namespace = $this->config->get('config_center.drivers.aliyun_acm.namespace', '');
|
||||||
@ -93,7 +72,7 @@ class Client implements ClientInterface
|
|||||||
try {
|
try {
|
||||||
if (! $this->servers) {
|
if (! $this->servers) {
|
||||||
// server list
|
// server list
|
||||||
$response = $client->get("http://{$endpoint}:8080/diamond-server/diamond");
|
$response = $this->client->get("http://{$endpoint}:8080/diamond-server/diamond");
|
||||||
if ($response->getStatusCode() !== 200) {
|
if ($response->getStatusCode() !== 200) {
|
||||||
throw new RuntimeException('Get server list failed from Aliyun ACM.');
|
throw new RuntimeException('Get server list failed from Aliyun ACM.');
|
||||||
}
|
}
|
||||||
@ -102,7 +81,7 @@ class Client implements ClientInterface
|
|||||||
$server = $this->servers[array_rand($this->servers)];
|
$server = $this->servers[array_rand($this->servers)];
|
||||||
|
|
||||||
// Get config
|
// Get config
|
||||||
$response = $client->get("http://{$server}:8080/diamond-server/config.co", [
|
$response = $this->client->get("http://{$server}:8080/diamond-server/config.co", [
|
||||||
'headers' => array_merge([
|
'headers' => array_merge([
|
||||||
'Spas-AccessKey' => $accessKey,
|
'Spas-AccessKey' => $accessKey,
|
||||||
'timeStamp' => $timestamp,
|
'timeStamp' => $timestamp,
|
||||||
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
|||||||
namespace Hyperf\ConfigApollo;
|
namespace Hyperf\ConfigApollo;
|
||||||
|
|
||||||
use Hyperf\ConfigCenter\AbstractDriver;
|
use Hyperf\ConfigCenter\AbstractDriver;
|
||||||
|
use Hyperf\ConfigCenter\Contract\ClientInterface;
|
||||||
use Hyperf\Engine\Channel;
|
use Hyperf\Engine\Channel;
|
||||||
use Hyperf\Utils\Coordinator\Constants;
|
use Hyperf\Utils\Coordinator\Constants;
|
||||||
use Hyperf\Utils\Coordinator\CoordinatorManager;
|
use Hyperf\Utils\Coordinator\CoordinatorManager;
|
||||||
@ -21,14 +22,14 @@ use Psr\Http\Message\ResponseInterface;
|
|||||||
|
|
||||||
class ApolloDriver extends AbstractDriver
|
class ApolloDriver extends AbstractDriver
|
||||||
{
|
{
|
||||||
|
protected string $driverName = 'apollo';
|
||||||
|
|
||||||
|
protected array $notifications = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ClientInterface
|
* @var \Hyperf\ConfigApollo\ClientInterface
|
||||||
*/
|
*/
|
||||||
protected $client;
|
protected ClientInterface $client;
|
||||||
|
|
||||||
protected $driverName = 'apollo';
|
|
||||||
|
|
||||||
protected $notifications = [];
|
|
||||||
|
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
@ -165,7 +166,7 @@ class ApolloDriver extends AbstractDriver
|
|||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function updateConfig(array $config)
|
protected function updateConfig(array $config): void
|
||||||
{
|
{
|
||||||
$mergedConfigs = [];
|
$mergedConfigs = [];
|
||||||
foreach ($config as $c) {
|
foreach ($config as $c) {
|
||||||
|
@ -20,41 +20,14 @@ use RuntimeException;
|
|||||||
|
|
||||||
class Client implements ClientInterface
|
class Client implements ClientInterface
|
||||||
{
|
{
|
||||||
/**
|
protected array $cache = [];
|
||||||
* @var ConfigInterface
|
|
||||||
*/
|
|
||||||
protected $config;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Option
|
|
||||||
*/
|
|
||||||
protected $option;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $cache = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Closure
|
|
||||||
*/
|
|
||||||
protected $httpClientFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Hyperf\Contract\StdoutLoggerInterface
|
|
||||||
*/
|
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Option $option,
|
protected Option $option,
|
||||||
Closure $httpClientFactory,
|
protected Closure $httpClientFactory,
|
||||||
ConfigInterface $config,
|
protected ConfigInterface $config,
|
||||||
StdoutLoggerInterface $logger
|
protected StdoutLoggerInterface $logger
|
||||||
) {
|
) {
|
||||||
$this->option = $option;
|
|
||||||
$this->httpClientFactory = $httpClientFactory;
|
|
||||||
$this->config = $config;
|
|
||||||
$this->logger = $logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function pull(): array
|
public function pull(): array
|
||||||
@ -95,7 +68,7 @@ class Client implements ClientInterface
|
|||||||
'query' => $query,
|
'query' => $query,
|
||||||
'headers' => $headers,
|
'headers' => $headers,
|
||||||
]);
|
]);
|
||||||
if ($response->getStatusCode() === 200 && strpos($response->getHeaderLine('Content-Type'), 'application/json') !== false) {
|
if ($response->getStatusCode() === 200 && str_contains($response->getHeaderLine('Content-Type'), 'application/json')) {
|
||||||
$body = json_decode((string) $response->getBody(), true);
|
$body = json_decode((string) $response->getBody(), true);
|
||||||
$result = $body['configurations'] ?? [];
|
$result = $body['configurations'] ?? [];
|
||||||
$this->cache[$cacheKey] = [
|
$this->cache[$cacheKey] = [
|
||||||
@ -133,7 +106,7 @@ class Client implements ClientInterface
|
|||||||
'notifications' => json_encode(array_values($notifications)),
|
'notifications' => json_encode(array_values($notifications)),
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
} catch (\Exception $exceptiosn) {
|
} catch (\Exception) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -15,45 +15,21 @@ use Hyperf\Utils\Str;
|
|||||||
|
|
||||||
class Option
|
class Option
|
||||||
{
|
{
|
||||||
/**
|
private string $server = '';
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $server = '';
|
|
||||||
|
|
||||||
/**
|
private string $appid = '';
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $appid = '';
|
|
||||||
|
|
||||||
/**
|
private array $namespaces = [];
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $namespaces = [];
|
|
||||||
|
|
||||||
/**
|
private string $cluster = 'default';
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $cluster = 'default';
|
|
||||||
|
|
||||||
/**
|
private string $clientIp = '127.0.0.1';
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $clientIp = '127.0.0.1';
|
|
||||||
|
|
||||||
/**
|
private int $pullTimeout = 10;
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
private $pullTimeout = 10;
|
|
||||||
|
|
||||||
/**
|
private int $intervalTimeout = 60;
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
private $intervalTimeout = 60;
|
|
||||||
|
|
||||||
/**
|
private string $secret = '';
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $secret;
|
|
||||||
|
|
||||||
public function buildBaseUrl(): string
|
public function buildBaseUrl(): string
|
||||||
{
|
{
|
||||||
@ -84,7 +60,7 @@ class Option
|
|||||||
return $this->server;
|
return $this->server;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setServer(string $server): self
|
public function setServer(string $server): static
|
||||||
{
|
{
|
||||||
if (! Str::startsWith($server, ['http://', 'https://'])) {
|
if (! Str::startsWith($server, ['http://', 'https://'])) {
|
||||||
$server = 'http://' . $server;
|
$server = 'http://' . $server;
|
||||||
@ -98,7 +74,7 @@ class Option
|
|||||||
return $this->appid;
|
return $this->appid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAppid(string $appid): self
|
public function setAppid(string $appid): static
|
||||||
{
|
{
|
||||||
$this->appid = $appid;
|
$this->appid = $appid;
|
||||||
return $this;
|
return $this;
|
||||||
@ -109,7 +85,7 @@ class Option
|
|||||||
return $this->namespaces;
|
return $this->namespaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setNamespaces(array $namespaces): self
|
public function setNamespaces(array $namespaces): static
|
||||||
{
|
{
|
||||||
$this->namespaces = $namespaces;
|
$this->namespaces = $namespaces;
|
||||||
return $this;
|
return $this;
|
||||||
@ -120,7 +96,7 @@ class Option
|
|||||||
return $this->cluster;
|
return $this->cluster;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCluster(string $cluster): self
|
public function setCluster(string $cluster): static
|
||||||
{
|
{
|
||||||
$this->cluster = $cluster;
|
$this->cluster = $cluster;
|
||||||
return $this;
|
return $this;
|
||||||
@ -131,7 +107,7 @@ class Option
|
|||||||
return $this->clientIp;
|
return $this->clientIp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setClientIp(string $clientIp): self
|
public function setClientIp(string $clientIp): static
|
||||||
{
|
{
|
||||||
$this->clientIp = $clientIp;
|
$this->clientIp = $clientIp;
|
||||||
return $this;
|
return $this;
|
||||||
@ -142,7 +118,7 @@ class Option
|
|||||||
return $this->pullTimeout;
|
return $this->pullTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setPullTimeout(int $pullTimeout): self
|
public function setPullTimeout(int $pullTimeout): static
|
||||||
{
|
{
|
||||||
$this->pullTimeout = $pullTimeout;
|
$this->pullTimeout = $pullTimeout;
|
||||||
return $this;
|
return $this;
|
||||||
@ -153,13 +129,13 @@ class Option
|
|||||||
return $this->intervalTimeout;
|
return $this->intervalTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setIntervalTimeout(int $intervalTimeout): self
|
public function setIntervalTimeout(int $intervalTimeout): static
|
||||||
{
|
{
|
||||||
$this->intervalTimeout = $intervalTimeout;
|
$this->intervalTimeout = $intervalTimeout;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSecret(string $secret): self
|
public function setSecret(string $secret): static
|
||||||
{
|
{
|
||||||
$this->secret = $secret;
|
$this->secret = $secret;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -21,6 +21,7 @@ use Hyperf\Utils\Coordinator\Constants;
|
|||||||
use Hyperf\Utils\Coordinator\CoordinatorManager;
|
use Hyperf\Utils\Coordinator\CoordinatorManager;
|
||||||
use Hyperf\Utils\Coroutine;
|
use Hyperf\Utils\Coroutine;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use Swoole\Server;
|
use Swoole\Server;
|
||||||
|
|
||||||
abstract class AbstractDriver implements DriverInterface
|
abstract class AbstractDriver implements DriverInterface
|
||||||
@ -30,39 +31,18 @@ abstract class AbstractDriver implements DriverInterface
|
|||||||
*/
|
*/
|
||||||
protected $server;
|
protected $server;
|
||||||
|
|
||||||
/**
|
protected ConfigInterface $config;
|
||||||
* @var null|ConfigInterface
|
|
||||||
*/
|
|
||||||
protected $config;
|
|
||||||
|
|
||||||
/**
|
protected LoggerInterface $logger;
|
||||||
* @var StdoutLoggerInterface
|
|
||||||
*/
|
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
/**
|
protected ClientInterface $client;
|
||||||
* @var ClientInterface
|
|
||||||
*/
|
|
||||||
protected $client;
|
|
||||||
|
|
||||||
/**
|
protected string $pipeMessage = PipeMessage::class;
|
||||||
* @var ContainerInterface
|
|
||||||
*/
|
|
||||||
protected $container;
|
|
||||||
|
|
||||||
/**
|
protected string $driverName = '';
|
||||||
* @var null|string
|
|
||||||
*/
|
|
||||||
protected $pipeMessage = PipeMessage::class;
|
|
||||||
|
|
||||||
/**
|
public function __construct(protected ContainerInterface $container)
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $driverName = '';
|
|
||||||
|
|
||||||
public function __construct(ContainerInterface $container)
|
|
||||||
{
|
{
|
||||||
$this->container = $container;
|
|
||||||
$this->config = $container->get(ConfigInterface::class);
|
$this->config = $container->get(ConfigInterface::class);
|
||||||
$this->logger = $container->get(StdoutLoggerInterface::class);
|
$this->logger = $container->get(StdoutLoggerInterface::class);
|
||||||
}
|
}
|
||||||
@ -94,7 +74,7 @@ abstract class AbstractDriver implements DriverInterface
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetchConfig()
|
public function fetchConfig(): void
|
||||||
{
|
{
|
||||||
if (method_exists($this->client, 'pull')) {
|
if (method_exists($this->client, 'pull')) {
|
||||||
$config = $this->pull();
|
$config = $this->pull();
|
||||||
@ -132,7 +112,7 @@ abstract class AbstractDriver implements DriverInterface
|
|||||||
return $this->client->pull();
|
return $this->client->pull();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function updateConfig(array $config)
|
protected function updateConfig(array $config): void
|
||||||
{
|
{
|
||||||
foreach ($config as $key => $value) {
|
foreach ($config as $key => $value) {
|
||||||
if (is_string($key)) {
|
if (is_string($key)) {
|
||||||
|
@ -11,7 +11,6 @@ declare(strict_types=1);
|
|||||||
*/
|
*/
|
||||||
namespace Hyperf\ConfigCenter;
|
namespace Hyperf\ConfigCenter;
|
||||||
|
|
||||||
use Hyperf\ConfigCenter\Listener\BootApplicationListener;
|
|
||||||
use Hyperf\ConfigCenter\Listener\CreateMessageFetcherLoopListener;
|
use Hyperf\ConfigCenter\Listener\CreateMessageFetcherLoopListener;
|
||||||
use Hyperf\ConfigCenter\Listener\FetchConfigOnBootListener;
|
use Hyperf\ConfigCenter\Listener\FetchConfigOnBootListener;
|
||||||
use Hyperf\ConfigCenter\Listener\OnPipeMessageListener;
|
use Hyperf\ConfigCenter\Listener\OnPipeMessageListener;
|
||||||
@ -30,7 +29,6 @@ class ConfigProvider
|
|||||||
ConfigFetcherProcess::class,
|
ConfigFetcherProcess::class,
|
||||||
],
|
],
|
||||||
'listeners' => [
|
'listeners' => [
|
||||||
BootApplicationListener::class,
|
|
||||||
FetchConfigOnBootListener::class,
|
FetchConfigOnBootListener::class,
|
||||||
CreateMessageFetcherLoopListener::class,
|
CreateMessageFetcherLoopListener::class,
|
||||||
OnPipeMessageListener::class,
|
OnPipeMessageListener::class,
|
||||||
|
@ -13,7 +13,7 @@ namespace Hyperf\ConfigCenter\Contract;
|
|||||||
|
|
||||||
interface DriverInterface
|
interface DriverInterface
|
||||||
{
|
{
|
||||||
public function fetchConfig();
|
public function fetchConfig(): void;
|
||||||
|
|
||||||
public function createMessageFetcherLoop(): void;
|
public function createMessageFetcherLoop(): void;
|
||||||
|
|
||||||
|
@ -16,14 +16,8 @@ use Hyperf\Contract\ConfigInterface;
|
|||||||
|
|
||||||
class DriverFactory
|
class DriverFactory
|
||||||
{
|
{
|
||||||
/**
|
public function __construct(protected ConfigInterface $config)
|
||||||
* @var ConfigInterface
|
|
||||||
*/
|
|
||||||
protected $config;
|
|
||||||
|
|
||||||
public function __construct(ConfigInterface $config)
|
|
||||||
{
|
{
|
||||||
$this->config = $config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(string $driver, array $properties = []): DriverInterface
|
public function create(string $driver, array $properties = []): DriverInterface
|
||||||
|
@ -1,59 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
/**
|
|
||||||
* This file is part of Hyperf.
|
|
||||||
*
|
|
||||||
* @link https://www.hyperf.io
|
|
||||||
* @document https://hyperf.wiki
|
|
||||||
* @contact group@hyperf.io
|
|
||||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
|
||||||
*/
|
|
||||||
namespace Hyperf\ConfigCenter\Listener;
|
|
||||||
|
|
||||||
use Hyperf\Contract\ConfigInterface;
|
|
||||||
use Hyperf\Event\Contract\ListenerInterface;
|
|
||||||
use Hyperf\Framework\Event\BootApplication;
|
|
||||||
use InvalidArgumentException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated v3.0
|
|
||||||
*/
|
|
||||||
class BootApplicationListener implements ListenerInterface
|
|
||||||
{
|
|
||||||
protected $config;
|
|
||||||
|
|
||||||
public function __construct(ConfigInterface $config)
|
|
||||||
{
|
|
||||||
$this->config = $config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function listen(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
BootApplication::class,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function process(object $event)
|
|
||||||
{
|
|
||||||
if ($this->config->get('config_center.enable', false)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$configs = [
|
|
||||||
'config_apollo',
|
|
||||||
'aliyun_acm',
|
|
||||||
'config_etcd',
|
|
||||||
'zookeeper',
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($configs as $config) {
|
|
||||||
if ($this->config->get($config . '.enable', false)) {
|
|
||||||
throw new InvalidArgumentException(
|
|
||||||
sprintf('Config [%s] is not supported, please use config_center instead.', $config)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -22,26 +22,11 @@ use Hyperf\Process\Event\PipeMessage as UserProcessPipeMessage;
|
|||||||
|
|
||||||
class OnPipeMessageListener implements ListenerInterface
|
class OnPipeMessageListener implements ListenerInterface
|
||||||
{
|
{
|
||||||
/**
|
public function __construct(
|
||||||
* @var \Hyperf\ConfigCenter\DriverFactory
|
protected DriverFactory $driverFactory,
|
||||||
*/
|
protected ConfigInterface $config,
|
||||||
protected $driverFactory;
|
protected StdoutLoggerInterface $logger
|
||||||
|
) {
|
||||||
/**
|
|
||||||
* @var ConfigInterface
|
|
||||||
*/
|
|
||||||
protected $config;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var StdoutLoggerInterface
|
|
||||||
*/
|
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
public function __construct(DriverFactory $driverFactory, ConfigInterface $config, StdoutLoggerInterface $logger)
|
|
||||||
{
|
|
||||||
$this->driverFactory = $driverFactory;
|
|
||||||
$this->config = $config;
|
|
||||||
$this->logger = $logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,14 +15,8 @@ use Hyperf\ConfigCenter\Contract\PipeMessageInterface;
|
|||||||
|
|
||||||
class PipeMessage implements PipeMessageInterface
|
class PipeMessage implements PipeMessageInterface
|
||||||
{
|
{
|
||||||
/**
|
public function __construct(protected array $data)
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $data = [];
|
|
||||||
|
|
||||||
public function __construct(array $data)
|
|
||||||
{
|
{
|
||||||
$this->data = $data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getData(): array
|
public function getData(): array
|
||||||
|
@ -18,6 +18,7 @@ use Hyperf\Contract\StdoutLoggerInterface;
|
|||||||
use Hyperf\Process\AbstractProcess;
|
use Hyperf\Process\AbstractProcess;
|
||||||
use Hyperf\Process\ProcessManager;
|
use Hyperf\Process\ProcessManager;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use Swoole\Server;
|
use Swoole\Server;
|
||||||
|
|
||||||
class ConfigFetcherProcess extends AbstractProcess
|
class ConfigFetcherProcess extends AbstractProcess
|
||||||
@ -29,20 +30,11 @@ class ConfigFetcherProcess extends AbstractProcess
|
|||||||
*/
|
*/
|
||||||
protected $server;
|
protected $server;
|
||||||
|
|
||||||
/**
|
protected ConfigInterface $config;
|
||||||
* @var ConfigInterface
|
|
||||||
*/
|
|
||||||
protected $config;
|
|
||||||
|
|
||||||
/**
|
protected LoggerInterface $logger;
|
||||||
* @var StdoutLoggerInterface
|
|
||||||
*/
|
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
/**
|
protected DriverFactory $driverFactory;
|
||||||
* @var \Hyperf\ConfigCenter\DriverFactory
|
|
||||||
*/
|
|
||||||
protected $driverFactory;
|
|
||||||
|
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
|
@ -16,20 +16,8 @@ use Hyperf\Etcd\KVInterface;
|
|||||||
|
|
||||||
class Client implements ClientInterface
|
class Client implements ClientInterface
|
||||||
{
|
{
|
||||||
/**
|
public function __construct(protected KVInterface $client, protected ConfigInterface $config)
|
||||||
* @var KVInterface
|
|
||||||
*/
|
|
||||||
protected $client;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var ConfigInterface
|
|
||||||
*/
|
|
||||||
protected $config;
|
|
||||||
|
|
||||||
public function __construct(KVInterface $client, ConfigInterface $config)
|
|
||||||
{
|
{
|
||||||
$this->client = $client;
|
|
||||||
$this->config = $config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function pull(): array
|
public function pull(): array
|
||||||
|
@ -12,22 +12,17 @@ declare(strict_types=1);
|
|||||||
namespace Hyperf\ConfigEtcd;
|
namespace Hyperf\ConfigEtcd;
|
||||||
|
|
||||||
use Hyperf\ConfigCenter\AbstractDriver;
|
use Hyperf\ConfigCenter\AbstractDriver;
|
||||||
|
use Hyperf\Contract\PackerInterface;
|
||||||
use Hyperf\Utils\Packer\JsonPacker;
|
use Hyperf\Utils\Packer\JsonPacker;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
|
|
||||||
class EtcdDriver extends AbstractDriver
|
class EtcdDriver extends AbstractDriver
|
||||||
{
|
{
|
||||||
/**
|
protected PackerInterface $packer;
|
||||||
* @var JsonPacker
|
|
||||||
*/
|
|
||||||
protected $packer;
|
|
||||||
|
|
||||||
/**
|
protected array $mapping = [];
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $mapping;
|
|
||||||
|
|
||||||
protected $driverName = 'etcd';
|
protected string $driverName = 'etcd';
|
||||||
|
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
@ -37,7 +32,7 @@ class EtcdDriver extends AbstractDriver
|
|||||||
$this->packer = $container->get($this->config->get('config_center.drivers.etcd.packer', JsonPacker::class));
|
$this->packer = $container->get($this->config->get('config_center.drivers.etcd.packer', JsonPacker::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function updateConfig(array $config)
|
protected function updateConfig(array $config): void
|
||||||
{
|
{
|
||||||
$configurations = $this->format($config);
|
$configurations = $this->format($config);
|
||||||
foreach ($configurations as $kv) {
|
foreach ($configurations as $kv) {
|
||||||
|
@ -13,30 +13,15 @@ namespace Hyperf\ConfigEtcd;
|
|||||||
|
|
||||||
class KV
|
class KV
|
||||||
{
|
{
|
||||||
/**
|
public ?string $key;
|
||||||
* @var null|string
|
|
||||||
*/
|
|
||||||
public $key;
|
|
||||||
|
|
||||||
/**
|
public ?string $createRevision;
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $createRevision;
|
|
||||||
|
|
||||||
/**
|
public ?string $modRevision;
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $modRevision;
|
|
||||||
|
|
||||||
/**
|
public ?string $version;
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $version;
|
|
||||||
|
|
||||||
/**
|
public ?string $value;
|
||||||
* @var null|string
|
|
||||||
*/
|
|
||||||
public $value;
|
|
||||||
|
|
||||||
public function __construct($data)
|
public function __construct($data)
|
||||||
{
|
{
|
||||||
|
@ -18,32 +18,18 @@ use Hyperf\Nacos\Exception\RequestException;
|
|||||||
use Hyperf\Utils\Codec\Json;
|
use Hyperf\Utils\Codec\Json;
|
||||||
use Hyperf\Utils\Codec\Xml;
|
use Hyperf\Utils\Codec\Xml;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Client implements ClientInterface
|
class Client implements ClientInterface
|
||||||
{
|
{
|
||||||
/**
|
protected ConfigInterface $config;
|
||||||
* @var ContainerInterface
|
|
||||||
*/
|
|
||||||
protected $container;
|
|
||||||
|
|
||||||
/**
|
protected Application $client;
|
||||||
* @var ConfigInterface
|
|
||||||
*/
|
|
||||||
protected $config;
|
|
||||||
|
|
||||||
/**
|
protected LoggerInterface $logger;
|
||||||
* @var Application
|
|
||||||
*/
|
|
||||||
protected $client;
|
|
||||||
|
|
||||||
/**
|
public function __construct(protected ContainerInterface $container)
|
||||||
* @var StdoutLoggerInterface
|
|
||||||
*/
|
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
public function __construct(ContainerInterface $container)
|
|
||||||
{
|
{
|
||||||
$this->container = $container;
|
|
||||||
$this->config = $container->get(ConfigInterface::class);
|
$this->config = $container->get(ConfigInterface::class);
|
||||||
$this->client = $container->get(NacosClient::class);
|
$this->client = $container->get(NacosClient::class);
|
||||||
$this->logger = $container->get(StdoutLoggerInterface::class);
|
$this->logger = $container->get(StdoutLoggerInterface::class);
|
||||||
@ -70,10 +56,7 @@ class Client implements ClientInterface
|
|||||||
return $config;
|
return $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function decode(string $body, ?string $type = null): array|string
|
||||||
* @return array|string
|
|
||||||
*/
|
|
||||||
public function decode(string $body, ?string $type = null)
|
|
||||||
{
|
{
|
||||||
$type = strtolower((string) $type);
|
$type = strtolower((string) $type);
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
@ -17,12 +17,7 @@ use Psr\Container\ContainerInterface;
|
|||||||
|
|
||||||
class NacosDriver extends AbstractDriver
|
class NacosDriver extends AbstractDriver
|
||||||
{
|
{
|
||||||
/**
|
protected string $driverName = 'nacos';
|
||||||
* @var Client
|
|
||||||
*/
|
|
||||||
protected $client;
|
|
||||||
|
|
||||||
protected $driverName = 'nacos';
|
|
||||||
|
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
@ -30,7 +25,7 @@ class NacosDriver extends AbstractDriver
|
|||||||
$this->client = $container->get(ClientInterface::class);
|
$this->client = $container->get(ClientInterface::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function updateConfig(array $config)
|
protected function updateConfig(array $config): void
|
||||||
{
|
{
|
||||||
$root = $this->config->get('config_center.drivers.nacos.default_key');
|
$root = $this->config->get('config_center.drivers.nacos.default_key');
|
||||||
foreach ($config as $key => $conf) {
|
foreach ($config as $key => $conf) {
|
||||||
|
@ -12,19 +12,12 @@ declare(strict_types=1);
|
|||||||
namespace Hyperf\ConfigZookeeper;
|
namespace Hyperf\ConfigZookeeper;
|
||||||
|
|
||||||
use Hyperf\Contract\ConfigInterface;
|
use Hyperf\Contract\ConfigInterface;
|
||||||
use Psr\Container\ContainerInterface;
|
|
||||||
use Swoole\Zookeeper;
|
use Swoole\Zookeeper;
|
||||||
|
|
||||||
class Client implements ClientInterface
|
class Client implements ClientInterface
|
||||||
{
|
{
|
||||||
/**
|
public function __construct(private ConfigInterface $config)
|
||||||
* @var ConfigInterface
|
|
||||||
*/
|
|
||||||
private $config;
|
|
||||||
|
|
||||||
public function __construct(ContainerInterface $container)
|
|
||||||
{
|
{
|
||||||
$this->config = $container->get(ConfigInterface::class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function pull(): array
|
public function pull(): array
|
||||||
|
@ -16,7 +16,7 @@ use Psr\Container\ContainerInterface;
|
|||||||
|
|
||||||
class ZookeeperDriver extends AbstractDriver
|
class ZookeeperDriver extends AbstractDriver
|
||||||
{
|
{
|
||||||
protected $driverName = 'zookeeper';
|
protected string $driverName = 'zookeeper';
|
||||||
|
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
|
@ -14,17 +14,10 @@ namespace Hyperf\Config\Annotation;
|
|||||||
use Attribute;
|
use Attribute;
|
||||||
use Hyperf\Di\Annotation\AbstractAnnotation;
|
use Hyperf\Di\Annotation\AbstractAnnotation;
|
||||||
|
|
||||||
/**
|
|
||||||
* @Annotation
|
|
||||||
* @Target({"PROPERTY"})
|
|
||||||
*/
|
|
||||||
#[Attribute(Attribute::TARGET_PROPERTY)]
|
#[Attribute(Attribute::TARGET_PROPERTY)]
|
||||||
class Value extends AbstractAnnotation
|
class Value extends AbstractAnnotation
|
||||||
{
|
{
|
||||||
/**
|
public ?string $key = null;
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $key;
|
|
||||||
|
|
||||||
public function __construct(...$value)
|
public function __construct(...$value)
|
||||||
{
|
{
|
||||||
|
@ -16,14 +16,8 @@ use Hyperf\Utils\Arr;
|
|||||||
|
|
||||||
class Config implements ConfigInterface
|
class Config implements ConfigInterface
|
||||||
{
|
{
|
||||||
/**
|
public function __construct(private array $configs)
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $configs = [];
|
|
||||||
|
|
||||||
public function __construct(array $configs)
|
|
||||||
{
|
{
|
||||||
$this->configs = $configs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,7 +27,7 @@ class Config implements ConfigInterface
|
|||||||
* @param mixed $default default value of the entry when does not found
|
* @param mixed $default default value of the entry when does not found
|
||||||
* @return mixed entry
|
* @return mixed entry
|
||||||
*/
|
*/
|
||||||
public function get(string $key, $default = null)
|
public function get(string $key, mixed $default = null): mixed
|
||||||
{
|
{
|
||||||
return data_get($this->configs, $key, $default);
|
return data_get($this->configs, $key, $default);
|
||||||
}
|
}
|
||||||
@ -43,9 +37,8 @@ class Config implements ConfigInterface
|
|||||||
* Returns false otherwise.
|
* Returns false otherwise.
|
||||||
*
|
*
|
||||||
* @param string $key identifier of the entry to look for
|
* @param string $key identifier of the entry to look for
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function has(string $key)
|
public function has(string $key): bool
|
||||||
{
|
{
|
||||||
return Arr::has($this->configs, $key);
|
return Arr::has($this->configs, $key);
|
||||||
}
|
}
|
||||||
@ -56,7 +49,7 @@ class Config implements ConfigInterface
|
|||||||
* @param string $key identifier of the entry to set
|
* @param string $key identifier of the entry to set
|
||||||
* @param mixed $value the value that save to container
|
* @param mixed $value the value that save to container
|
||||||
*/
|
*/
|
||||||
public function set(string $key, $value)
|
public function set(string $key, mixed $value): void
|
||||||
{
|
{
|
||||||
data_set($this->configs, $key, $value);
|
data_set($this->configs, $key, $value);
|
||||||
}
|
}
|
||||||
|
@ -21,10 +21,7 @@ use function method_exists;
|
|||||||
*/
|
*/
|
||||||
class ProviderConfig
|
class ProviderConfig
|
||||||
{
|
{
|
||||||
/**
|
private static array $providerConfigs = [];
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private static $providerConfigs = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load and merge all provider configs from components.
|
* Load and merge all provider configs from components.
|
||||||
|
@ -20,16 +20,15 @@ interface ConfigInterface
|
|||||||
* @param mixed $default default value of the entry when does not found
|
* @param mixed $default default value of the entry when does not found
|
||||||
* @return mixed entry
|
* @return mixed entry
|
||||||
*/
|
*/
|
||||||
public function get(string $key, $default = null);
|
public function get(string $key, mixed $default = null): mixed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the container can return an entry for the given identifier.
|
* Returns true if the container can return an entry for the given identifier.
|
||||||
* Returns false otherwise.
|
* Returns false otherwise.
|
||||||
*
|
*
|
||||||
* @param string $keys identifier of the entry to look for
|
* @param string $keys identifier of the entry to look for
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function has(string $keys);
|
public function has(string $keys): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a value to the container by its identifier.
|
* Set a value to the container by its identifier.
|
||||||
@ -37,5 +36,5 @@ interface ConfigInterface
|
|||||||
* @param string $key identifier of the entry to set
|
* @param string $key identifier of the entry to set
|
||||||
* @param mixed $value the value that save to container
|
* @param mixed $value the value that save to container
|
||||||
*/
|
*/
|
||||||
public function set(string $key, $value);
|
public function set(string $key, mixed $value): void;
|
||||||
}
|
}
|
||||||
|
@ -29,13 +29,13 @@ class ProtocolManager
|
|||||||
|
|
||||||
public function register(string $name, array $data)
|
public function register(string $name, array $data)
|
||||||
{
|
{
|
||||||
return $this->config->set('protocols.' . $name, $data);
|
$this->config->set('protocols.' . $name, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function registerOrAppend(string $name, array $data)
|
public function registerOrAppend(string $name, array $data)
|
||||||
{
|
{
|
||||||
$key = 'protocols.' . $name;
|
$key = 'protocols.' . $name;
|
||||||
return $this->config->set($key, array_merge($this->config->get($key, []), $data));
|
$this->config->set($key, array_merge($this->config->get($key, []), $data));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getProtocol(string $name): array
|
public function getProtocol(string $name): array
|
||||||
|
Loading…
Reference in New Issue
Block a user