Skip to content

Commit 27586d5

Browse files
authored
Cancel grpc-server's dependency on hyperf/rpc. (#5554)
1 parent 3e7ff05 commit 27586d5

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/Listener/RegisterProtocolListener.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
use Hyperf\GrpcClient\GrpcPacker;
2020
use Hyperf\GrpcClient\GrpcTransporter;
2121
use Hyperf\Rpc\ProtocolManager;
22+
use Psr\Container\ContainerInterface;
2223

2324
class RegisterProtocolListener implements ListenerInterface
2425
{
25-
public function __construct(private ProtocolManager $protocolManager)
26+
public function __construct(private ContainerInterface $container)
2627
{
2728
}
2829

@@ -39,12 +40,15 @@ public function listen(): array
3940
*/
4041
public function process(object $event): void
4142
{
42-
$this->protocolManager->register('grpc', [
43-
'packer' => GrpcPacker::class,
44-
'transporter' => GrpcTransporter::class,
45-
'path-generator' => PathGenerator::class,
46-
'data-formatter' => DataFormatter::class,
47-
'normalizer' => GrpcNormalizer::class,
48-
]);
43+
if ($this->container->has(ProtocolManager::class)) {
44+
$manager = $this->container->get(ProtocolManager::class);
45+
$manager->register('grpc', [
46+
'packer' => GrpcPacker::class,
47+
'transporter' => GrpcTransporter::class,
48+
'path-generator' => PathGenerator::class,
49+
'data-formatter' => DataFormatter::class,
50+
'normalizer' => GrpcNormalizer::class,
51+
]);
52+
}
4953
}
5054
}

0 commit comments

Comments
 (0)