44
55use Aws \Sqs \SqsClient ;
66use Interop \Queue \InvalidDestinationException ;
7+ use Interop \Queue \PsrConsumer ;
78use Interop \Queue \PsrContext ;
89use Interop \Queue \PsrDestination ;
10+ use Interop \Queue \PsrMessage ;
11+ use Interop \Queue \PsrProducer ;
12+ use Interop \Queue \PsrQueue ;
13+ use Interop \Queue \PsrSubscriptionConsumer ;
14+ use Interop \Queue \PsrTopic ;
15+ use Interop \Queue \SubscriptionConsumerNotSupportedException ;
16+ use Interop \Queue \TemporaryQueueNotSupportedException ;
917
1018class SqsContext implements PsrContext
1119{
@@ -45,78 +53,76 @@ public function __construct($client)
4553 }
4654
4755 /**
48- * {@inheritdoc}
49- *
5056 * @return SqsMessage
5157 */
52- public function createMessage ($ body = '' , array $ properties = [], array $ headers = [])
58+ public function createMessage (string $ body = '' , array $ properties = [], array $ headers = []): PsrMessage
5359 {
5460 return new SqsMessage ($ body , $ properties , $ headers );
5561 }
5662
5763 /**
58- * {@inheritdoc}
59- *
6064 * @return SqsDestination
6165 */
62- public function createTopic ($ topicName )
66+ public function createTopic (string $ topicName ): PsrTopic
6367 {
6468 return new SqsDestination ($ topicName );
6569 }
6670
6771 /**
68- * {@inheritdoc}
69- *
7072 * @return SqsDestination
7173 */
72- public function createQueue ($ queueName )
74+ public function createQueue (string $ queueName ): PsrQueue
7375 {
7476 return new SqsDestination ($ queueName );
7577 }
7678
77- /**
78- * {@inheritdoc}
79- */
80- public function createTemporaryQueue ()
79+ public function createTemporaryQueue (): PsrQueue
8180 {
82- throw new \ BadMethodCallException ( ' SQS transport does not support temporary queues ' );
81+ throw TemporaryQueueNotSupportedException :: providerDoestNotSupportIt ( );
8382 }
8483
8584 /**
86- * {@inheritdoc}
87- *
8885 * @return SqsProducer
8986 */
90- public function createProducer ()
87+ public function createProducer (): PsrProducer
9188 {
9289 return new SqsProducer ($ this );
9390 }
9491
9592 /**
96- * {@inheritdoc}
97- *
9893 * @param SqsDestination $destination
9994 *
10095 * @return SqsConsumer
10196 */
102- public function createConsumer (PsrDestination $ destination )
97+ public function createConsumer (PsrDestination $ destination ): PsrConsumer
10398 {
10499 InvalidDestinationException ::assertDestinationInstanceOf ($ destination , SqsDestination::class);
105100
106101 return new SqsConsumer ($ this , $ destination );
107102 }
108103
109- /**
110- * {@inheritdoc}
111- */
112- public function close ()
104+ public function close (): void
113105 {
114106 }
115107
116108 /**
117- * @return SqsClient
109+ * @param SqsDestination $queue
118110 */
119- public function getClient ()
111+ public function purgeQueue (PsrQueue $ queue ): void
112+ {
113+ InvalidDestinationException ::assertDestinationInstanceOf ($ queue , SqsDestination::class);
114+
115+ $ this ->getClient ()->purgeQueue ([
116+ 'QueueUrl ' => $ this ->getQueueUrl ($ queue ),
117+ ]);
118+ }
119+
120+ public function createSubscriptionConsumer (): PsrSubscriptionConsumer
121+ {
122+ throw SubscriptionConsumerNotSupportedException ::providerDoestNotSupportIt ();
123+ }
124+
125+ public function getClient (): SqsClient
120126 {
121127 if (false == $ this ->client ) {
122128 $ client = call_user_func ($ this ->clientFactory );
@@ -134,12 +140,7 @@ public function getClient()
134140 return $ this ->client ;
135141 }
136142
137- /**
138- * @param SqsDestination $destination
139- *
140- * @return string
141- */
142- public function getQueueUrl (SqsDestination $ destination )
143+ public function getQueueUrl (SqsDestination $ destination ): string
143144 {
144145 if (isset ($ this ->queueUrls [$ destination ->getQueueName ()])) {
145146 return $ this ->queueUrls [$ destination ->getQueueName ()];
@@ -156,10 +157,7 @@ public function getQueueUrl(SqsDestination $destination)
156157 return $ this ->queueUrls [$ destination ->getQueueName ()] = $ result ->get ('QueueUrl ' );
157158 }
158159
159- /**
160- * @param SqsDestination $dest
161- */
162- public function declareQueue (SqsDestination $ dest )
160+ public function declareQueue (SqsDestination $ dest ): void
163161 {
164162 $ result = $ this ->getClient ()->createQueue ([
165163 'Attributes ' => $ dest ->getAttributes (),
@@ -173,25 +171,12 @@ public function declareQueue(SqsDestination $dest)
173171 $ this ->queueUrls [$ dest ->getQueueName ()] = $ result ->get ('QueueUrl ' );
174172 }
175173
176- /**
177- * @param SqsDestination $dest
178- */
179- public function deleteQueue (SqsDestination $ dest )
174+ public function deleteQueue (SqsDestination $ dest ): void
180175 {
181176 $ this ->getClient ()->deleteQueue ([
182177 'QueueUrl ' => $ this ->getQueueUrl ($ dest ),
183178 ]);
184179
185180 unset($ this ->queueUrls [$ dest ->getQueueName ()]);
186181 }
187-
188- /**
189- * @param SqsDestination $destination
190- */
191- public function purgeQueue (SqsDestination $ destination )
192- {
193- $ this ->getClient ()->purgeQueue ([
194- 'QueueUrl ' => $ this ->getQueueUrl ($ destination ),
195- ]);
196- }
197182}
0 commit comments