5
5
6
6
use ApacheBorys \Retry \ExceptionHandler ;
7
7
use ApacheBorys \Retry \HandlerExceptionDeclarator \PublicCallbackDeclarator ;
8
+ use ApacheBorys \Retry \HandlerFactory ;
8
9
use ApacheBorys \Retry \MessageHandler ;
9
10
use Psr \Container \ContainerInterface ;
10
11
use Psr \Log \LoggerInterface ;
@@ -25,26 +26,43 @@ public function load(array $configs, ContainerBuilder $container): void
25
26
$ configuration = new ConfigSchema ();
26
27
$ config = $ this ->processConfiguration ($ configuration , $ configs );
27
28
29
+ $ this ->normalizeConfig ($ config );
30
+
31
+ $ container ->setDefinition (
32
+ 'retry.exception_handler_factory ' ,
33
+ new Definition (HandlerFactory::class, [$ config , new Reference (LoggerInterface::class)])
34
+ );
35
+
36
+ $ container ->setDefinition (ExceptionHandler::class, $ this ->defineExceptionHandler ());
37
+
38
+ $ container ->setDefinition (MessageHandler::class, $ this ->defineMessageHandler ());
39
+ }
40
+
41
+ private function normalizeConfig (array &$ config ): void
42
+ {
28
43
if (!isset ($ config ['handlerExceptionDeclarator ' ])) {
29
44
$ config ['handlerExceptionDeclarator ' ]['class ' ] = PublicCallbackDeclarator::class;
30
45
$ config ['handlerExceptionDeclarator ' ]['arguments ' ] = [];
31
46
}
47
+ }
32
48
33
- $ definitionForExceptionHandler = new Definition (
34
- ExceptionHandler::class,
35
- [ $ config , new Reference (LoggerInterface::class), new Reference (ContainerInterface ::class)]
36
- );
37
- $ definitionForExceptionHandler -> addMethodCall ( ' initHandler ' );
38
- $ definitionForExceptionHandler ->setPublic (true );
49
+ private function defineExceptionHandler (): Definition
50
+ {
51
+ $ exceptionHandlerDefinition = new Definition (ExceptionHandler ::class);
52
+ $ exceptionHandlerDefinition -> setFactory ([ new Reference ( ' retry.exception_handler_factory ' ), ' createExceptionHandler ' ] );
53
+ $ exceptionHandlerDefinition -> addArgument ( new Reference (ContainerInterface::class) );
54
+ $ exceptionHandlerDefinition ->setPublic (true );
39
55
40
- $ container ->setDefinition (ExceptionHandler::class, $ definitionForExceptionHandler );
56
+ return $ exceptionHandlerDefinition ;
57
+ }
41
58
42
- $ definitionForMessageHandler = new Definition (
43
- MessageHandler::class,
44
- [$ config , new Reference (LoggerInterface::class), new Reference (ContainerInterface::class)]
45
- );
46
- $ definitionForMessageHandler ->setPublic (true );
59
+ private function defineMessageHandler (): Definition
60
+ {
61
+ $ messageHandlerDefinition = new Definition (MessageHandler::class);
62
+ $ messageHandlerDefinition ->setFactory ([new Reference ('retry.exception_handler_factory ' ), 'createMessageHandler ' ]);
63
+ $ messageHandlerDefinition ->addArgument (new Reference (ContainerInterface::class));
64
+ $ messageHandlerDefinition ->setPublic (true );
47
65
48
- $ container -> setDefinition (MessageHandler::class, $ definitionForMessageHandler ) ;
66
+ return $ messageHandlerDefinition ;
49
67
}
50
68
}
0 commit comments