Skip to content

Commit

Permalink
Add setTopicArn methods to SnsContext and SnsQsContext
Browse files Browse the repository at this point in the history
  • Loading branch information
gdsmith committed Aug 18, 2021
1 parent 3880257 commit 425d5e0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
5 changes: 5 additions & 0 deletions pkg/sns/SnsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public function declareTopic(SnsDestination $destination): void
$this->topicArns[$destination->getTopicName()] = (string) $result->get('TopicArn');
}

public function setTopicArn(SnsDestination $destination, string $arn): void
{
$this->topicArns[$destination->getTopicName()] = $arn;
}

public function deleteTopic(SnsDestination $destination): void
{
$this->client->deleteTopic($this->getTopicArn($destination));
Expand Down
29 changes: 9 additions & 20 deletions pkg/snsqs/SnsQsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,15 @@ public function __construct($snsContext, $sqsContext)
} elseif (is_callable($snsContext)) {
$this->snsContextFactory = $snsContext;
} else {
throw new \InvalidArgumentException(sprintf(
'The $snsContext argument must be either %s or callable that returns %s once called.',
SnsContext::class,
SnsContext::class
));
throw new \InvalidArgumentException(sprintf('The $snsContext argument must be either %s or callable that returns %s once called.', SnsContext::class, SnsContext::class));
}

if ($sqsContext instanceof SqsContext) {
$this->sqsContext = $sqsContext;
} elseif (is_callable($sqsContext)) {
$this->sqsContextFactory = $sqsContext;
} else {
throw new \InvalidArgumentException(sprintf(
'The $sqsContext argument must be either %s or callable that returns %s once called.',
SqsContext::class,
SqsContext::class
));
throw new \InvalidArgumentException(sprintf('The $sqsContext argument must be either %s or callable that returns %s once called.', SqsContext::class, SqsContext::class));
}
}

Expand Down Expand Up @@ -137,6 +129,11 @@ public function declareTopic(SnsQsTopic $topic): void
$this->getSnsContext()->declareTopic($topic);
}

public function setTopicArn(SnsQsTopic $topic, string $arn): void
{
$this->getSnsContext()->setTopicArn($topic);
}

public function deleteTopic(SnsQsTopic $topic): void
{
$this->getSnsContext()->deleteTopic($topic);
Expand Down Expand Up @@ -181,11 +178,7 @@ private function getSnsContext(): SnsContext
if (null === $this->snsContext) {
$context = call_user_func($this->snsContextFactory);
if (false == $context instanceof SnsContext) {
throw new \LogicException(sprintf(
'The factory must return instance of %s. It returned %s',
SnsContext::class,
is_object($context) ? get_class($context) : gettype($context)
));
throw new \LogicException(sprintf('The factory must return instance of %s. It returned %s', SnsContext::class, is_object($context) ? get_class($context) : gettype($context)));
}

$this->snsContext = $context;
Expand All @@ -199,11 +192,7 @@ private function getSqsContext(): SqsContext
if (null === $this->sqsContext) {
$context = call_user_func($this->sqsContextFactory);
if (false == $context instanceof SqsContext) {
throw new \LogicException(sprintf(
'The factory must return instance of %s. It returned %s',
SqsContext::class,
is_object($context) ? get_class($context) : gettype($context)
));
throw new \LogicException(sprintf('The factory must return instance of %s. It returned %s', SqsContext::class, is_object($context) ? get_class($context) : gettype($context)));
}

$this->sqsContext = $context;
Expand Down

0 comments on commit 425d5e0

Please sign in to comment.