Skip to content

[Sqs] Allow array-based DSN configuration #315

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 6 commits into from
Jan 13, 2018
Merged
Show file tree
Hide file tree
Changes from 3 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
15 changes: 11 additions & 4 deletions pkg/sqs/SqsConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,18 @@ public function __construct($config = 'sqs:')
{
if (empty($config) || 'sqs:' === $config) {
$config = [];
} elseif (is_string($config)) {
}

if (is_string($config)) {
$config = $this->parseDsn($config);
} elseif (is_array($config)) {
} else {
throw new \LogicException('The config must be either an array of options, a DSN string or null');
}

if (!is_array($config)) {
throw new \LogicException('The config must be either an array of options, a DSN string, or null');
}

if (count($config) == 1 && array_key_exists('dsn', $config)) {
Copy link
Member

Choose a reason for hiding this comment

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

dsn option could be used with other options in config. It should work like here

The config is treat as default options, and options from dsn could overwrite them

$config = $this->parseDsn($config['dsn']);
}

$this->config = array_replace($this->defaultConfig(), $config);
Expand Down
15 changes: 14 additions & 1 deletion pkg/sqs/Tests/SqsConnectionFactoryConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SqsConnectionFactoryConfigTest extends TestCase
public function testThrowNeitherArrayStringNorNullGivenAsConfig()
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('The config must be either an array of options, a DSN string or null');
$this->expectExceptionMessage('The config must be either an array of options, a DSN string, or null');

new SqsConnectionFactory(new \stdClass());
}
Expand Down Expand Up @@ -104,6 +104,19 @@ public static function provideConfigs()
],
];

yield [
['dsn' => 'sqs:?key=theKey&secret=theSecret&token=theToken&lazy=0'],
[
'key' => 'theKey',
'secret' => 'theSecret',
'token' => 'theToken',
'region' => null,
'retries' => 3,
'version' => '2012-11-05',
'lazy' => false,
],
];

yield [
['key' => 'theKey', 'secret' => 'theSecret', 'token' => 'theToken', 'lazy' => false],
[
Expand Down