44
55namespace Enqueue \Sqs ;
66
7- use Aws \Sqs \SqsClient ;
7+ use Aws \Sqs \SqsClient as AwsSqsClient ;
88use Interop \Queue \Consumer ;
99use Interop \Queue \Context ;
1010use Interop \Queue \Destination ;
@@ -24,37 +24,19 @@ class SqsContext implements Context
2424 */
2525 private $ client ;
2626
27- /**
28- * @var callable
29- */
30- private $ clientFactory ;
31-
3227 /**
3328 * @var array
3429 */
3530 private $ queueUrls ;
3631
37- private $ config ;
38-
3932 /**
40- * Callable must return instance of SqsClient once called.
41- *
42- * @param SqsClient|callable $client
33+ * @var array
4334 */
44- public function __construct ($ client , array $ config )
45- {
46- if ($ client instanceof SqsClient) {
47- $ this ->client = $ client ;
48- } elseif (is_callable ($ client )) {
49- $ this ->clientFactory = $ client ;
50- } else {
51- throw new \InvalidArgumentException (sprintf (
52- 'The $client argument must be either %s or callable that returns %s once called. ' ,
53- SqsClient::class,
54- SqsClient::class
55- ));
56- }
35+ private $ config ;
5736
37+ public function __construct (SqsClient $ client , array $ config )
38+ {
39+ $ this ->client = $ client ;
5840 $ this ->config = $ config ;
5941 }
6042
@@ -118,7 +100,7 @@ public function purgeQueue(Queue $queue): void
118100 {
119101 InvalidDestinationException ::assertDestinationInstanceOf ($ queue , SqsDestination::class);
120102
121- $ this ->getClient () ->purgeQueue ([
103+ $ this ->client ->purgeQueue ([
122104 '@region ' => $ queue ->getRegion (),
123105 'QueueUrl ' => $ this ->getQueueUrl ($ queue ),
124106 ]);
@@ -129,24 +111,26 @@ public function createSubscriptionConsumer(): SubscriptionConsumer
129111 throw SubscriptionConsumerNotSupportedException ::providerDoestNotSupportIt ();
130112 }
131113
132- public function getClient (): SqsClient
114+ public function getAwsSqsClient (): AwsSqsClient
133115 {
134- if (false == $ this ->client ) {
135- $ client = call_user_func ($ this ->clientFactory );
136- if (false == $ client instanceof SqsClient) {
137- throw new \LogicException (sprintf (
138- 'The factory must return instance of "%s". But it returns %s ' ,
139- SqsClient::class,
140- is_object ($ client ) ? get_class ($ client ) : gettype ($ client )
141- ));
142- }
143-
144- $ this ->client = $ client ;
145- }
116+ return $ this ->client ->getAWSClient ();
117+ }
146118
119+ public function getSqsClient (): SqsClient
120+ {
147121 return $ this ->client ;
148122 }
149123
124+ /**
125+ * @deprecated use getAwsSqsClient method
126+ */
127+ public function getClient (): AwsSqsClient
128+ {
129+ @trigger_error ('The method is deprecated since 0.9.2. SqsContext::getAwsSqsClient() method should be used. ' , E_USER_DEPRECATED );
130+
131+ return $ this ->getAwsSqsClient ();
132+ }
133+
150134 public function getQueueUrl (SqsDestination $ destination ): string
151135 {
152136 if (isset ($ this ->queueUrls [$ destination ->getQueueName ()])) {
@@ -155,7 +139,7 @@ public function getQueueUrl(SqsDestination $destination): string
155139
156140 $ arguments = [
157141 '@region ' => $ destination ->getRegion (),
158- 'QueueName ' => $ destination ->getQueueName ()
142+ 'QueueName ' => $ destination ->getQueueName (),
159143 ];
160144
161145 if ($ destination ->getQueueOwnerAWSAccountId ()) {
@@ -164,7 +148,7 @@ public function getQueueUrl(SqsDestination $destination): string
164148 $ arguments ['QueueOwnerAWSAccountId ' ] = $ this ->config ['queue_owner_aws_account_id ' ];
165149 }
166150
167- $ result = $ this ->getClient () ->getQueueUrl ($ arguments );
151+ $ result = $ this ->client ->getQueueUrl ($ arguments );
168152
169153 if (false == $ result ->hasKey ('QueueUrl ' )) {
170154 throw new \RuntimeException (sprintf ('QueueUrl cannot be resolved. queueName: "%s" ' , $ destination ->getQueueName ()));
@@ -175,7 +159,7 @@ public function getQueueUrl(SqsDestination $destination): string
175159
176160 public function declareQueue (SqsDestination $ dest ): void
177161 {
178- $ result = $ this ->getClient () ->createQueue ([
162+ $ result = $ this ->client ->createQueue ([
179163 '@region ' => $ dest ->getRegion (),
180164 'Attributes ' => $ dest ->getAttributes (),
181165 'QueueName ' => $ dest ->getQueueName (),
@@ -190,7 +174,7 @@ public function declareQueue(SqsDestination $dest): void
190174
191175 public function deleteQueue (SqsDestination $ dest ): void
192176 {
193- $ this ->getClient () ->deleteQueue ([
177+ $ this ->client ->deleteQueue ([
194178 'QueueUrl ' => $ this ->getQueueUrl ($ dest ),
195179 ]);
196180
0 commit comments