改名
This commit is contained in:
+23
-7
@@ -5,7 +5,11 @@ namespace Rpc;
|
|||||||
|
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use JetBrains\PhpStorm\ArrayShape;
|
||||||
|
use ReflectionException;
|
||||||
use Snowflake\Abstracts\Component;
|
use Snowflake\Abstracts\Component;
|
||||||
|
use Snowflake\Exception\ComponentException;
|
||||||
|
use Snowflake\Exception\NotFindClassException;
|
||||||
use Snowflake\Snowflake;
|
use Snowflake\Snowflake;
|
||||||
|
|
||||||
|
|
||||||
@@ -112,29 +116,41 @@ class Producer extends Component
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
|
* @param array|null $config
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @throws ComponentException
|
||||||
|
* @throws NotFindClassException
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function getClient(string $name): Client
|
public function getClient(string $name, array $config = null): Client
|
||||||
{
|
{
|
||||||
if (!is_array($producer = $this->producers[$name] ?? null)) {
|
$producer = $config ?? $this->producers[$name] ?? null;
|
||||||
|
if ($producer === null) {
|
||||||
throw new Exception('Unknown rpc client config.');
|
throw new Exception('Unknown rpc client config.');
|
||||||
}
|
}
|
||||||
$producerName = $this->getName($name, $producer);
|
$producerName = $this->getName($name, $producer);
|
||||||
|
|
||||||
$snowflake = Snowflake::app();
|
$snowflake = Snowflake::app();
|
||||||
if (!$snowflake->has($producerName)) {
|
if (!$snowflake->has($producerName)) {
|
||||||
return $snowflake->set($producerName, [
|
return $snowflake->set($producerName, $this->definer($name, $producer));
|
||||||
'class' => Client::class,
|
|
||||||
'service' => $name,
|
|
||||||
'config' => $producer
|
|
||||||
]);
|
|
||||||
} else {
|
} else {
|
||||||
return $snowflake->get($producerName);
|
return $snowflake->get($producerName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $name
|
||||||
|
* @param $producer
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function definer($name, $producer): array
|
||||||
|
{
|
||||||
|
return ['class' => Client::class, 'service' => $name, 'config' => $producer];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $name
|
* @param $name
|
||||||
* @return Client|bool
|
* @return Client|bool
|
||||||
|
|||||||
Reference in New Issue
Block a user