File tree Expand file tree Collapse file tree 2 files changed +34
-6
lines changed
src/Enqueue/Enqueue/Helper Expand file tree Collapse file tree 2 files changed +34
-6
lines changed Original file line number Diff line number Diff line change 2020// init
2121Mage::app ('admin ' , 'store ' );
2222
23- /** @var \Enqueue\Client\SimpleClient $client */
24- $ client = Mage::helper ('enqueue ' )->getClient ();
23+ /** @var \Enqueue_Enqueue_Helper_Data $enqueue */
24+ $ enqueue = Mage::helper ('enqueue ' );
25+ $ enqueue ->bindProcessors ();
2526
26- //bind message processor
27- //$helper = Mage::helper('helper-name');
28- //$client->bind('topic', 'consumer-name', [$helper, 'method-name']);
27+ /** @var \Enqueue\Client\SimpleClient $client */
28+ $ client = $ enqueue ->getClient ();
2929
3030$ application = new Application ();
31-
3231$ application ->add (new SetupBrokerCommand ($ client ->getDriver ()));
3332$ application ->add (new ProduceMessageCommand ($ client ->getProducer ()));
3433$ application ->add (new QueuesCommand ($ client ->getQueueMetaRegistry ()));
Original file line number Diff line number Diff line change 11<?php
22
3+ use Enqueue \Psr \PsrProcessor ;
4+
35class Enqueue_Enqueue_Helper_Data extends Mage_Core_Helper_Data
46{
57 /**
68 * @var \Enqueue\Client\SimpleClient
79 */
810 private $ client ;
911
12+ public function bindProcessors ()
13+ {
14+ if (false == $ processors = Mage::getStoreConfig ('enqueue/processors ' )) {
15+ return ;
16+ }
17+
18+ foreach ($ processors as $ name => $ config ) {
19+ if (empty ($ config ['topic ' ])) {
20+ throw new \LogicException ('Topic name is not set for processor: "%s" ' , $ name );
21+ }
22+
23+ if (empty ($ config ['helper ' ])) {
24+ throw new \LogicException ('Helper name is not set for processor: "%s" ' , $ name );
25+ }
26+
27+ $ this ->getClient ()->bind ($ config ['topic ' ], $ name , function () use ($ config ) {
28+ $ processor = Mage::helper ($ config ['helper ' ]);
29+
30+ if (false == $ processor instanceof PsrProcessor) {
31+ throw new \LogicException ();
32+ }
33+
34+ call_user_func_array ([$ processor , 'process ' ], func_get_args ());
35+ });
36+ }
37+ }
38+
1039 public function getClient ()
1140 {
1241 if (null === $ this ->client ) {
You can’t perform that action at this time.
0 commit comments