19
19
use Hyperf \GrpcClient \GrpcPacker ;
20
20
use Hyperf \GrpcClient \GrpcTransporter ;
21
21
use Hyperf \Rpc \ProtocolManager ;
22
+ use Psr \Container \ContainerInterface ;
22
23
23
24
class RegisterProtocolListener implements ListenerInterface
24
25
{
25
- public function __construct (private ProtocolManager $ protocolManager )
26
+ public function __construct (private ContainerInterface $ container )
26
27
{
27
28
}
28
29
@@ -39,12 +40,15 @@ public function listen(): array
39
40
*/
40
41
public function process (object $ event ): void
41
42
{
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
+ }
49
53
}
50
54
}
0 commit comments