|
3 | 3 | namespace Enqueue\Redis; |
4 | 4 |
|
5 | 5 | use Interop\Queue\InvalidDestinationException; |
| 6 | +use Interop\Queue\PsrConsumer; |
6 | 7 | use Interop\Queue\PsrContext; |
7 | 8 | use Interop\Queue\PsrDestination; |
| 9 | +use Interop\Queue\PsrMessage; |
| 10 | +use Interop\Queue\PsrProducer; |
8 | 11 | use Interop\Queue\PsrQueue; |
9 | | -use Interop\Queue\PsrSubscriptionConsumerAwareContext; |
| 12 | +use Interop\Queue\PsrSubscriptionConsumer; |
10 | 13 | use Interop\Queue\PsrTopic; |
| 14 | +use Interop\Queue\TemporaryQueueNotSupportedException; |
11 | 15 |
|
12 | | -class RedisContext implements PsrContext, PsrSubscriptionConsumerAwareContext |
| 16 | +class RedisContext implements PsrContext |
13 | 17 | { |
14 | 18 | /** |
15 | 19 | * @var Redis |
@@ -42,106 +46,96 @@ public function __construct($redis) |
42 | 46 | } |
43 | 47 |
|
44 | 48 | /** |
45 | | - * {@inheritdoc} |
46 | | - * |
47 | 49 | * @return RedisMessage |
48 | 50 | */ |
49 | | - public function createMessage($body = '', array $properties = [], array $headers = []) |
| 51 | + public function createMessage(string $body = '', array $properties = [], array $headers = []): PsrMessage |
50 | 52 | { |
51 | 53 | return new RedisMessage($body, $properties, $headers); |
52 | 54 | } |
53 | 55 |
|
54 | 56 | /** |
55 | | - * {@inheritdoc} |
56 | | - * |
57 | 57 | * @return RedisDestination |
58 | 58 | */ |
59 | | - public function createTopic($topicName) |
| 59 | + public function createTopic(string $topicName): PsrTopic |
60 | 60 | { |
61 | 61 | return new RedisDestination($topicName); |
62 | 62 | } |
63 | 63 |
|
64 | 64 | /** |
65 | | - * {@inheritdoc} |
66 | | - * |
67 | 65 | * @return RedisDestination |
68 | 66 | */ |
69 | | - public function createQueue($queueName) |
| 67 | + public function createQueue(string $queueName): PsrQueue |
70 | 68 | { |
71 | 69 | return new RedisDestination($queueName); |
72 | 70 | } |
73 | 71 |
|
74 | 72 | /** |
75 | | - * @param RedisDestination|PsrQueue $queue |
| 73 | + * @param RedisDestination $queue |
76 | 74 | */ |
77 | | - public function deleteQueue(PsrQueue $queue) |
| 75 | + public function deleteQueue(PsrQueue $queue): void |
78 | 76 | { |
79 | 77 | InvalidDestinationException::assertDestinationInstanceOf($queue, RedisDestination::class); |
80 | 78 |
|
81 | 79 | $this->getRedis()->del($queue->getName()); |
82 | 80 | } |
83 | 81 |
|
84 | 82 | /** |
85 | | - * @param RedisDestination|PsrTopic $topic |
| 83 | + * @param RedisDestination $topic |
86 | 84 | */ |
87 | | - public function deleteTopic(PsrTopic $topic) |
| 85 | + public function deleteTopic(PsrTopic $topic): void |
88 | 86 | { |
89 | 87 | InvalidDestinationException::assertDestinationInstanceOf($topic, RedisDestination::class); |
90 | 88 |
|
91 | 89 | $this->getRedis()->del($topic->getName()); |
92 | 90 | } |
93 | 91 |
|
94 | | - /** |
95 | | - * {@inheritdoc} |
96 | | - */ |
97 | | - public function createTemporaryQueue() |
| 92 | + public function createTemporaryQueue(): PsrQueue |
98 | 93 | { |
99 | | - throw new \LogicException('Not implemented'); |
| 94 | + throw TemporaryQueueNotSupportedException::providerDoestNotSupportIt(); |
100 | 95 | } |
101 | 96 |
|
102 | 97 | /** |
103 | | - * {@inheritdoc} |
104 | | - * |
105 | 98 | * @return RedisProducer |
106 | 99 | */ |
107 | | - public function createProducer() |
| 100 | + public function createProducer(): PsrProducer |
108 | 101 | { |
109 | 102 | return new RedisProducer($this->getRedis()); |
110 | 103 | } |
111 | 104 |
|
112 | 105 | /** |
113 | | - * {@inheritdoc} |
114 | | - * |
115 | 106 | * @param RedisDestination $destination |
116 | 107 | * |
117 | 108 | * @return RedisConsumer |
118 | 109 | */ |
119 | | - public function createConsumer(PsrDestination $destination) |
| 110 | + public function createConsumer(PsrDestination $destination): PsrConsumer |
120 | 111 | { |
121 | 112 | InvalidDestinationException::assertDestinationInstanceOf($destination, RedisDestination::class); |
122 | 113 |
|
123 | 114 | return new RedisConsumer($this, $destination); |
124 | 115 | } |
125 | 116 |
|
126 | 117 | /** |
127 | | - * {@inheritdoc} |
128 | | - * |
129 | 118 | * @return RedisSubscriptionConsumer |
130 | 119 | */ |
131 | | - public function createSubscriptionConsumer() |
| 120 | + public function createSubscriptionConsumer(): PsrSubscriptionConsumer |
132 | 121 | { |
133 | 122 | return new RedisSubscriptionConsumer($this); |
134 | 123 | } |
135 | 124 |
|
136 | | - public function close() |
| 125 | + /** |
| 126 | + * @param RedisDestination $queue |
| 127 | + */ |
| 128 | + public function purgeQueue(PsrQueue $queue): void |
| 129 | + { |
| 130 | + $this->getRedis()->del($queue->getName()); |
| 131 | + } |
| 132 | + |
| 133 | + public function close(): void |
137 | 134 | { |
138 | 135 | $this->getRedis()->disconnect(); |
139 | 136 | } |
140 | 137 |
|
141 | | - /** |
142 | | - * @return Redis |
143 | | - */ |
144 | | - public function getRedis() |
| 138 | + public function getRedis(): Redis |
145 | 139 | { |
146 | 140 | if (false == $this->redis) { |
147 | 141 | $redis = call_user_func($this->redisFactory); |
|
0 commit comments