Skip to content

Add setTopicArn methods to SnsContext and SnsQsContext #1189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any particular reason for these formatting changes? IMO they reduce readability.

}

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