22
33namespace Enqueue \Monitoring \Symfony \DependencyInjection ;
44
5+ use Enqueue \Monitoring \ClientMonitoringExtension ;
6+ use Enqueue \Monitoring \ConsumerMonitoringExtension ;
57use Enqueue \Monitoring \GenericStatsStorageFactory ;
68use Enqueue \Monitoring \Resources ;
79use Enqueue \Monitoring \StatsStorage ;
810use Enqueue \Monitoring \StatsStorageFactory ;
9- use Enqueue \Symfony \DependencyInjection \ FormatTransportNameTrait ;
11+ use Enqueue \Symfony \DiUtils ;
1012use Symfony \Component \Config \Definition \Builder \ArrayNodeDefinition ;
1113use Symfony \Component \DependencyInjection \ContainerBuilder ;
1214use Symfony \Component \DependencyInjection \Reference ;
1618 */
1719final class MonitoringFactory
1820{
19- use FormatTransportNameTrait;
20-
2121 /**
22- * @var string
22+ * @var DiUtils
2323 */
24- private $ name ;
24+ private $ diUtils ;
2525
2626 public function __construct (string $ name )
2727 {
2828 if (empty ($ name )) {
2929 throw new \InvalidArgumentException ('The name could not be empty. ' );
3030 }
3131
32- $ this ->name = $ name ;
32+ $ this ->diUtils = DiUtils:: create ( ' monitoring ' , $ name) ;
3333 }
3434
3535 public function getConfiguration (string $ name ): ArrayNodeDefinition
@@ -74,15 +74,10 @@ public function getConfiguration(string $name): ArrayNodeDefinition
7474 return $ builder ;
7575 }
7676
77- public function getName (): string
78- {
79- return $ this ->name ;
80- }
81-
8277 public function buildStorage (ContainerBuilder $ container , array $ config ): void
8378 {
84- $ storageId = $ this ->format ('storage ' );
85- $ storageFactoryId = $ this ->format ('storage.factory ' );
79+ $ storageId = $ this ->diUtils -> format ('storage ' );
80+ $ storageFactoryId = $ this ->diUtils -> format ('storage.factory ' );
8681
8782 if (isset ($ config ['storage_factory_service ' ])) {
8883 $ container ->setAlias ($ storageFactoryId , $ config ['storage_factory_service ' ]);
@@ -99,4 +94,22 @@ public function buildStorage(ContainerBuilder $container, array $config): void
9994 ->addArgument ($ config )
10095 ;
10196 }
97+
98+ public function buildClientExtension (ContainerBuilder $ container , array $ config ): void
99+ {
100+ $ container ->register ($ this ->diUtils ->format ('client_extension ' ), ClientMonitoringExtension::class)
101+ ->addArgument ($ this ->diUtils ->reference ('storage ' ))
102+ ->addArgument (new Reference ('logger ' ))
103+ ->addTag ('enqueue.client_extension ' , ['client ' => $ this ->diUtils ->getConfigName ()])
104+ ;
105+ }
106+
107+ public function buildConsumerExtension (ContainerBuilder $ container , array $ config ): void
108+ {
109+ $ container ->register ($ this ->diUtils ->format ('consumer_extension ' ), ConsumerMonitoringExtension::class)
110+ ->addArgument ($ this ->diUtils ->reference ('storage ' ))
111+ ->addTag ('enqueue.consumption_extension ' , ['client ' => $ this ->diUtils ->getConfigName ()])
112+ ->addTag ('enqueue.transport.consumption_extension ' , ['transport ' => $ this ->diUtils ->getConfigName ()])
113+ ;
114+ }
102115}
0 commit comments