22
33namespace Enqueue \Bundle \DependencyInjection \Compiler ;
44
5+ use Enqueue \Client \CommandSubscriberInterface ;
6+ use Enqueue \Client \Config ;
57use Enqueue \Client \TopicSubscriberInterface ;
68use Symfony \Component \DependencyInjection \ContainerBuilder ;
79use Symfony \Component \DependencyInjection \Exception \ParameterNotFoundException ;
@@ -43,7 +45,43 @@ protected function extractSubscriptions(ContainerBuilder $container, $processorS
4345 ];
4446
4547 $ data = [];
48+ if (is_subclass_of ($ processorClass , CommandSubscriberInterface::class)) {
49+ /** @var CommandSubscriberInterface $processorClass */
50+ $ params = $ processorClass ::getSubscribedCommand ();
51+ if (is_string ($ params )) {
52+ if (empty ($ params )) {
53+ throw new \LogicException ('The command name must not be empty ' );
54+ }
55+
56+ $ data [] = [
57+ 'topicName ' => Config::COMMAND_TOPIC ,
58+ 'queueName ' => $ defaultQueueName ,
59+ 'queueNameHardcoded ' => false ,
60+ 'processorName ' => $ params ,
61+ ];
62+ } elseif (is_array ($ params )) {
63+ $ params = array_replace ($ subscriptionPrototype , $ params );
64+
65+ if ($ processorName = $ resolve ($ params ['processorName ' ])) {
66+ throw new \LogicException ('The processor name (it is also the command name) must not be empty. ' );
67+ }
68+
69+ $ data [] = [
70+ 'topicName ' => Config::COMMAND_TOPIC ,
71+ 'queueName ' => $ resolve ($ params ['queueName ' ]) ?: $ defaultQueueName ,
72+ 'queueNameHardcoded ' => $ resolve ($ params ['queueNameHardcoded ' ]),
73+ 'processorName ' => $ processorName ,
74+ ];
75+ } else {
76+ throw new \LogicException (sprintf (
77+ 'Command subscriber configuration is invalid. "%s" ' ,
78+ json_encode ($ processorClass ::getSubscribedCommand ())
79+ ));
80+ }
81+ }
82+
4683 if (is_subclass_of ($ processorClass , TopicSubscriberInterface::class)) {
84+ /** @var TopicSubscriberInterface $processorClass */
4785 foreach ($ processorClass ::getSubscribedTopics () as $ topicName => $ params ) {
4886 if (is_string ($ params )) {
4987 $ data [] = [
@@ -68,7 +106,12 @@ protected function extractSubscriptions(ContainerBuilder $container, $processorS
68106 ));
69107 }
70108 }
71- } else {
109+ }
110+
111+ if (false == (
112+ is_subclass_of ($ processorClass , CommandSubscriberInterface::class) ||
113+ is_subclass_of ($ processorClass , TopicSubscriberInterface::class)
114+ )) {
72115 foreach ($ tagAttributes as $ tagAttribute ) {
73116 $ tagAttribute = array_replace ($ subscriptionPrototype , $ tagAttribute );
74117
0 commit comments