From 7c7a7f4d6e2d53f5be70e2937da046dbe63306da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Wed, 24 Mar 2021 18:51:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Rpc/Producer.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Rpc/Producer.php b/Rpc/Producer.php index 0da1303a..cca6bf86 100644 --- a/Rpc/Producer.php +++ b/Rpc/Producer.php @@ -5,6 +5,7 @@ namespace Rpc; use Exception; +use JetBrains\PhpStorm\ArrayShape; use ReflectionException; use Snowflake\Abstracts\Component; use Snowflake\Exception\ComponentException; @@ -128,6 +129,10 @@ class Producer extends Component if ($producer === null) { throw new Exception('Unknown rpc client config.'); } + + if (!isset($producer['host'])) { + $producer['host'] = Snowflake::localhost(); + } $producerName = $this->getName($name, $producer); $snowflake = Snowflake::app(); @@ -144,6 +149,7 @@ class Producer extends Component * @param $producer * @return array */ + #[ArrayShape(['class' => "string", 'service' => "", 'config' => ""])] private function definer($name, $producer): array { return ['class' => Client::class, 'service' => $name, 'config' => $producer]; @@ -163,12 +169,12 @@ class Producer extends Component /** * @param $name - * @param $rand + * @param $config * @return string */ - private function getName($name, $rand): string + private function getName($name, $config): string { - return 'rpc.client.' . $name . '.' . $rand['host']; + return 'rpc.client.' . $name . '.' . $config['host']; } }