mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-05 05:07:58 +08:00
Uniform the name to Driver
This commit is contained in:
parent
4199d3a49b
commit
e4a792c613
@ -22,8 +22,8 @@ use Hyperf\Rpc\IdGenerator;
|
||||
use Hyperf\Rpc\Protocol;
|
||||
use Hyperf\Rpc\ProtocolManager;
|
||||
use Hyperf\RpcClient\Exception\RequestException;
|
||||
use Hyperf\ServiceGovernance\ServiceGovernanceInterface;
|
||||
use Hyperf\ServiceGovernance\ServiceGovernanceManager;
|
||||
use Hyperf\ServiceGovernance\DriverInterface;
|
||||
use Hyperf\ServiceGovernance\DriverManager;
|
||||
use InvalidArgumentException;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use RuntimeException;
|
||||
@ -191,8 +191,8 @@ abstract class AbstractServiceClient
|
||||
$registryProtocol = $consumer['registry']['protocol'] ?? null;
|
||||
$registryAddress = $consumer['registry']['address'] ?? null;
|
||||
// Current $consumer is the config of the specified consumer.
|
||||
if (! empty($registryProtocol) && ! empty($registryAddress) && $this->container->has(ServiceGovernanceManager::class)) {
|
||||
$governance = $this->container->get(ServiceGovernanceManager::class)->get($registryProtocol);
|
||||
if (! empty($registryProtocol) && ! empty($registryAddress) && $this->container->has(DriverManager::class)) {
|
||||
$governance = $this->container->get(DriverManager::class)->get($registryProtocol);
|
||||
if (! $governance) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid protocol of registry %s', $registryProtocol));
|
||||
}
|
||||
@ -221,7 +221,7 @@ abstract class AbstractServiceClient
|
||||
throw new InvalidArgumentException('Config of registry or nodes missing.');
|
||||
}
|
||||
|
||||
protected function getNodes(ServiceGovernanceInterface $governance, string $address): array
|
||||
protected function getNodes(DriverInterface $governance, string $address): array
|
||||
{
|
||||
$nodeArray = $governance->getNodes($address, $this->serviceName, [
|
||||
'protocol' => $this->protocol,
|
||||
|
@ -11,7 +11,7 @@ declare(strict_types=1);
|
||||
*/
|
||||
namespace Hyperf\ServiceGovernance;
|
||||
|
||||
use Hyperf\ServiceGovernance\Listener\RegisterServiceGovernanceListener;
|
||||
use Hyperf\ServiceGovernance\Listener\RegisterDriverListener;
|
||||
use Hyperf\ServiceGovernance\Listener\RegisterServiceListener;
|
||||
use Hyperf\ServiceGovernance\Register\ConsulAgent;
|
||||
use Hyperf\ServiceGovernance\Register\ConsulAgentFactory;
|
||||
@ -26,7 +26,7 @@ class ConfigProvider
|
||||
IPReaderInterface::class => IPReader::class,
|
||||
],
|
||||
'listeners' => [
|
||||
RegisterServiceGovernanceListener::class,
|
||||
RegisterDriverListener::class,
|
||||
RegisterServiceListener::class,
|
||||
],
|
||||
'annotations' => [
|
||||
|
@ -21,7 +21,7 @@ use Hyperf\ServiceGovernance\Exception\ComponentRequiredException;
|
||||
use Hyperf\ServiceGovernance\Register\ConsulAgent;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class ConsulGovernance implements ServiceGovernanceInterface
|
||||
class ConsulDriver implements DriverInterface
|
||||
{
|
||||
/**
|
||||
* @var ContainerInterface
|
@ -11,7 +11,7 @@ declare(strict_types=1);
|
||||
*/
|
||||
namespace Hyperf\ServiceGovernance;
|
||||
|
||||
interface ServiceGovernanceInterface
|
||||
interface DriverInterface
|
||||
{
|
||||
/**
|
||||
* @param $metadata = [
|
30
src/service-governance/src/DriverManager.php
Normal file
30
src/service-governance/src/DriverManager.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?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\ServiceGovernance;
|
||||
|
||||
class DriverManager
|
||||
{
|
||||
/**
|
||||
* @var DriverInterface[]
|
||||
*/
|
||||
protected $drivers = [];
|
||||
|
||||
public function register(string $name, DriverInterface $governance)
|
||||
{
|
||||
$this->drivers[$name] = $governance;
|
||||
}
|
||||
|
||||
public function get(string $name): ?DriverInterface
|
||||
{
|
||||
return $this->drivers[$name] ?? null;
|
||||
}
|
||||
}
|
@ -13,19 +13,19 @@ namespace Hyperf\ServiceGovernance\Listener;
|
||||
|
||||
use Hyperf\Event\Contract\ListenerInterface;
|
||||
use Hyperf\Framework\Event\BootApplication;
|
||||
use Hyperf\ServiceGovernance\ConsulGovernance;
|
||||
use Hyperf\ServiceGovernance\ServiceGovernanceManager;
|
||||
use Hyperf\ServiceGovernance\ConsulDriver;
|
||||
use Hyperf\ServiceGovernance\DriverManager;
|
||||
|
||||
class RegisterServiceGovernanceListener implements ListenerInterface
|
||||
class RegisterDriverListener implements ListenerInterface
|
||||
{
|
||||
/**
|
||||
* @var ServiceGovernanceManager
|
||||
* @var DriverManager
|
||||
*/
|
||||
protected $manager;
|
||||
protected $driverManager;
|
||||
|
||||
public function __construct(ServiceGovernanceManager $manager)
|
||||
public function __construct(DriverManager $manager)
|
||||
{
|
||||
$this->manager = $manager;
|
||||
$this->driverManager = $manager;
|
||||
}
|
||||
|
||||
public function listen(): array
|
||||
@ -37,6 +37,6 @@ class RegisterServiceGovernanceListener implements ListenerInterface
|
||||
|
||||
public function process(object $event)
|
||||
{
|
||||
$this->manager->register('consul', make(ConsulGovernance::class));
|
||||
$this->driverManager->register('consul', make(ConsulDriver::class));
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ use Hyperf\Framework\Event\MainWorkerStart;
|
||||
use Hyperf\Server\Event\MainCoroutineServerStart;
|
||||
use Hyperf\ServiceGovernance\IPReaderInterface;
|
||||
use Hyperf\ServiceGovernance\Register\ConsulAgent;
|
||||
use Hyperf\ServiceGovernance\ServiceGovernanceManager;
|
||||
use Hyperf\ServiceGovernance\DriverManager;
|
||||
use Hyperf\ServiceGovernance\ServiceManager;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
@ -51,7 +51,7 @@ class RegisterServiceListener implements ListenerInterface
|
||||
protected $ipReader;
|
||||
|
||||
/**
|
||||
* @var ServiceGovernanceManager
|
||||
* @var DriverManager
|
||||
*/
|
||||
protected $governanceManager;
|
||||
|
||||
@ -62,7 +62,7 @@ class RegisterServiceListener implements ListenerInterface
|
||||
$this->serviceManager = $container->get(ServiceManager::class);
|
||||
$this->config = $container->get(ConfigInterface::class);
|
||||
$this->ipReader = $container->get(IPReaderInterface::class);
|
||||
$this->governanceManager = $container->get(ServiceGovernanceManager::class);
|
||||
$this->governanceManager = $container->get(DriverManager::class);
|
||||
}
|
||||
|
||||
public function listen(): array
|
||||
@ -85,7 +85,7 @@ class RegisterServiceListener implements ListenerInterface
|
||||
$servers = $this->getServers();
|
||||
foreach ($services as $serviceName => $serviceProtocols) {
|
||||
foreach ($serviceProtocols as $paths) {
|
||||
foreach ($paths as $path => $service) {
|
||||
foreach ($paths as $service) {
|
||||
if (! isset($service['publishTo'], $service['server'])) {
|
||||
continue;
|
||||
}
|
||||
|
@ -1,30 +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\ServiceGovernance;
|
||||
|
||||
class ServiceGovernanceManager
|
||||
{
|
||||
/**
|
||||
* @var ServiceGovernanceInterface[]
|
||||
*/
|
||||
protected $governance = [];
|
||||
|
||||
public function register(string $name, ServiceGovernanceInterface $governance)
|
||||
{
|
||||
$this->governance[$name] = $governance;
|
||||
}
|
||||
|
||||
public function get(string $name): ?ServiceGovernanceInterface
|
||||
{
|
||||
return $this->governance[$name] ?? null;
|
||||
}
|
||||
}
|
@ -17,12 +17,12 @@ use Hyperf\Consul\ConsulResponse;
|
||||
use Hyperf\Contract\ConfigInterface;
|
||||
use Hyperf\Contract\StdoutLoggerInterface;
|
||||
use Hyperf\Logger\Logger;
|
||||
use Hyperf\ServiceGovernance\ConsulGovernance;
|
||||
use Hyperf\ServiceGovernance\ConsulDriver;
|
||||
use Hyperf\ServiceGovernance\IPReader;
|
||||
use Hyperf\ServiceGovernance\IPReaderInterface;
|
||||
use Hyperf\ServiceGovernance\Listener\RegisterServiceListener;
|
||||
use Hyperf\ServiceGovernance\Register\ConsulAgent;
|
||||
use Hyperf\ServiceGovernance\ServiceGovernanceManager;
|
||||
use Hyperf\ServiceGovernance\DriverManager;
|
||||
use Hyperf\ServiceGovernance\ServiceManager;
|
||||
use Mockery;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
@ -149,8 +149,8 @@ class RegisterServiceListenerTest extends TestCase
|
||||
],
|
||||
]));
|
||||
$container->shouldReceive('get')->with(IPReaderInterface::class)->andReturn(new IPReader());
|
||||
$container->shouldReceive('get')->with(ServiceGovernanceManager::class)->andReturn($manager = new ServiceGovernanceManager());
|
||||
$manager->register('consul', new ConsulGovernance($container));
|
||||
$container->shouldReceive('get')->with(DriverManager::class)->andReturn($manager = new DriverManager());
|
||||
$manager->register('consul', new ConsulDriver($container));
|
||||
return $container;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user