diff --git a/pkg/sns/SnsConnectionFactory.php b/pkg/sns/SnsConnectionFactory.php index b3efd90d7..67903ba22 100644 --- a/pkg/sns/SnsConnectionFactory.php +++ b/pkg/sns/SnsConnectionFactory.php @@ -24,13 +24,14 @@ class SnsConnectionFactory implements ConnectionFactory /** * $config = [ - * 'key' => null AWS credentials. If no credentials are provided, the SDK will attempt to load them from the environment. + * 'key' => null, AWS credentials. If no credentials are provided, the SDK will attempt to load them from the environment. * 'secret' => null, AWS credentials. If no credentials are provided, the SDK will attempt to load them from the environment. * 'token' => null, AWS credentials. If no credentials are provided, the SDK will attempt to load them from the environment. * 'region' => null, (string, required) Region to connect to. See http://docs.aws.amazon.com/general/latest/gr/rande.html for a list of available regions. * 'version' => '2012-11-05', (string, required) The version of the webservice to utilize * 'lazy' => true, Enable lazy connection (boolean) - * 'endpoint' => null (string, default=null) The full URI of the webservice. This is only required when connecting to a custom endpoint e.g. localstack + * 'endpoint' => null, (string, default=null) The full URI of the webservice. This is only required when connecting to a custom endpoint e.g. localstack + * 'topic_arns' => [], (array) The list of existing topic arns: key - topic name; value - arn * ]. * * or @@ -132,6 +133,7 @@ private function parseDsn(string $dsn): array 'version' => $dsn->getString('version'), 'lazy' => $dsn->getBool('lazy'), 'endpoint' => $dsn->getString('endpoint'), + 'topic_arns' => $dsn->getArray('topic_arns', [])->toArray(), ]), function ($value) { return null !== $value; }); } @@ -145,6 +147,7 @@ private function defaultConfig(): array 'version' => '2010-03-31', 'lazy' => true, 'endpoint' => null, + 'topic_arns' => [], ]; } } diff --git a/pkg/sns/SnsContext.php b/pkg/sns/SnsContext.php index b489f8d57..aa00be1aa 100644 --- a/pkg/sns/SnsContext.php +++ b/pkg/sns/SnsContext.php @@ -35,8 +35,7 @@ public function __construct(SnsClient $client, array $config) { $this->client = $client; $this->config = $config; - - $this->topicArns = []; + $this->topicArns = $config['topic_arns']; } /** diff --git a/pkg/sns/Tests/SnsConnectionFactoryConfigTest.php b/pkg/sns/Tests/SnsConnectionFactoryConfigTest.php index 5dd3a2baa..51983b126 100644 --- a/pkg/sns/Tests/SnsConnectionFactoryConfigTest.php +++ b/pkg/sns/Tests/SnsConnectionFactoryConfigTest.php @@ -64,6 +64,7 @@ public static function provideConfigs() 'version' => '2010-03-31', 'lazy' => true, 'endpoint' => null, + 'topic_arns' => [], ], ]; @@ -77,6 +78,7 @@ public static function provideConfigs() 'version' => '2010-03-31', 'lazy' => true, 'endpoint' => null, + 'topic_arns' => [], ], ]; @@ -90,6 +92,7 @@ public static function provideConfigs() 'version' => '2010-03-31', 'lazy' => true, 'endpoint' => null, + 'topic_arns' => [], ], ]; @@ -103,6 +106,7 @@ public static function provideConfigs() 'version' => '2010-03-31', 'lazy' => false, 'endpoint' => null, + 'topic_arns' => [], ], ]; @@ -116,6 +120,7 @@ public static function provideConfigs() 'version' => '2010-03-31', 'lazy' => false, 'endpoint' => null, + 'topic_arns' => [], ], ]; @@ -129,6 +134,7 @@ public static function provideConfigs() 'version' => '2010-03-31', 'lazy' => false, 'endpoint' => null, + 'topic_arns' => [], ], ]; @@ -148,6 +154,24 @@ public static function provideConfigs() 'version' => '2010-03-31', 'lazy' => false, 'endpoint' => 'http://localstack:1111', + 'topic_arns' => [], + ], + ]; + + yield [ + ['dsn' => 'sns:?topic_arns[topic1]=arn:aws:sns:us-east-1:123456789012:topic1&topic_arns[topic2]=arn:aws:sns:us-west-2:123456789012:topic2'], + [ + 'key' => null, + 'secret' => null, + 'token' => null, + 'region' => null, + 'version' => '2010-03-31', + 'lazy' => true, + 'endpoint' => null, + 'topic_arns' => [ + 'topic1' => 'arn:aws:sns:us-east-1:123456789012:topic1', + 'topic2' => 'arn:aws:sns:us-west-2:123456789012:topic2', + ], ], ]; } diff --git a/pkg/sns/Tests/SnsConnectionFactoryTest.php b/pkg/sns/Tests/SnsConnectionFactoryTest.php index 37fe6043a..5cc8f197b 100644 --- a/pkg/sns/Tests/SnsConnectionFactoryTest.php +++ b/pkg/sns/Tests/SnsConnectionFactoryTest.php @@ -33,6 +33,7 @@ public function testCouldBeConstructedWithEmptyConfiguration() 'region' => null, 'version' => '2010-03-31', 'endpoint' => null, + 'topic_arns' => [], ], 'config', $factory); } @@ -48,6 +49,7 @@ public function testCouldBeConstructedWithCustomConfiguration() 'region' => null, 'version' => '2010-03-31', 'endpoint' => null, + 'topic_arns' => [], ], 'config', $factory); } diff --git a/pkg/sns/Tests/Spec/SnsContextTest.php b/pkg/sns/Tests/Spec/SnsContextTest.php index 631d4acf1..6713abad0 100644 --- a/pkg/sns/Tests/Spec/SnsContextTest.php +++ b/pkg/sns/Tests/Spec/SnsContextTest.php @@ -20,6 +20,6 @@ protected function createContext() { $client = $this->createMock(SnsClient::class); - return new SnsContext($client, []); + return new SnsContext($client, ['topic_arns' => []]); } }