1 | <?php |
||
18 | class PredisSubscribeCommandQueue implements SubscribeCommandQueue |
||
19 | { |
||
20 | /** |
||
21 | * @var RedisPubSubAdapter |
||
22 | */ |
||
23 | private $client; |
||
24 | |||
25 | /** |
||
26 | * @var Serializer |
||
27 | */ |
||
28 | private $serializer; |
||
29 | |||
30 | /** |
||
31 | * @var LoggerInterface |
||
32 | */ |
||
33 | private $logger; |
||
34 | |||
35 | /** |
||
36 | * @var callable[] |
||
37 | */ |
||
38 | private $handlers = []; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | private $queue_name = ''; |
||
44 | |||
45 | /** |
||
46 | * @var bool |
||
47 | */ |
||
48 | private $subscribed = false; |
||
49 | |||
50 | /** |
||
51 | * @param RedisPubSubAdapter $client |
||
52 | * @param Serializer $serializer |
||
53 | * @param LoggerInterface $logger |
||
54 | * @param string $queue_name |
||
55 | */ |
||
56 | public function __construct( |
||
57 | RedisPubSubAdapter $client, |
||
58 | Serializer $serializer, |
||
59 | LoggerInterface $logger, |
||
60 | $queue_name |
||
61 | ) { |
||
62 | $this->client = $client; |
||
63 | $this->serializer = $serializer; |
||
64 | $this->logger = $logger; |
||
65 | $this->queue_name = $queue_name; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Publish command to queue. |
||
70 | * |
||
71 | * @param Command $command |
||
72 | * |
||
73 | * @return bool |
||
74 | */ |
||
75 | public function publish(Command $command) |
||
82 | |||
83 | /** |
||
84 | * Subscribe on command queue. |
||
85 | * |
||
86 | * @param callable $handler |
||
87 | */ |
||
88 | public function subscribe(callable $handler) |
||
100 | |||
101 | /** |
||
102 | * Unsubscribe on command queue. |
||
103 | * |
||
104 | * @param callable $handler |
||
105 | * |
||
106 | * @return bool |
||
107 | */ |
||
108 | public function unsubscribe(callable $handler) |
||
120 | |||
121 | /** |
||
122 | * @param mixed $message |
||
123 | */ |
||
124 | private function handle($message) |
||
143 | } |
||
144 |