Skip to content

Commit ccb1380

Browse files
authored
feat: Support using fully configured DynamoDbClient via new dynamodb_client option (#20)
1 parent de95299 commit ccb1380

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/LaunchDarkly/Impl/Integrations/DynamoDbFeatureRequester.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public function __construct(string $baseUri, string $sdkKey, array $options)
2626

2727
$dynamoDbOptions = $options['dynamodb_options'] ?? [];
2828
$dynamoDbOptions['version'] = '2012-08-10'; // in the AWS SDK for PHP, this is how you specify the API version
29-
$this->_client = new DynamoDbClient($dynamoDbOptions);
29+
$client = $options['dynamodb_client'] ?? null;
30+
$this->_client = $client instanceof DynamoDbClient ? $client : new DynamoDbClient($dynamoDbOptions);
3031

3132
$prefix = $options['dynamodb_prefix'] ?? '';
3233
$this->_prefix = ($prefix != null && $prefix != '') ? ($prefix . ':') : '';

src/LaunchDarkly/Integrations/DynamoDb.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
namespace LaunchDarkly\Integrations;
33

4-
use \LaunchDarkly\Impl\Integrations\DynamoDbFeatureRequester;
4+
use LaunchDarkly\Impl\Integrations\DynamoDbFeatureRequester;
55

66
class DynamoDb
77
{
@@ -10,9 +10,16 @@ class DynamoDb
1010
*
1111
* After calling this method, store its return value in the `feature_requester` property of your client configuration:
1212
*
13-
* $fr = LaunchDarkly\Integrations\DynamoDb::featureRequester([ "dynamodb_table" => "my-table" ]);
14-
* $config = [ "feature_requester" => $fr ];
15-
* $client = new LDClient("sdk_key", $config);
13+
* $fr = LaunchDarkly\Integrations\DynamoDb::featureRequester([ 'dynamodb_table' => 'my-table' ]);
14+
* $config = [ 'feature_requester' => $fr ];
15+
* $client = new LDClient('sdk_key', $config);
16+
*
17+
* Or if you already have a client instance:
18+
*
19+
* $dynamoClient = new Aws\DynamoDb\DynamoDbClient($settings);
20+
* $fr = LaunchDarkly\Integrations\DynamoDb::featureRequester([ 'dynamo_client' => $dynamoClient ]);
21+
* $config = [ 'feature_requester' => $fr ];
22+
* $client = new LDClient('sdk_key', $config);
1623
*
1724
* For more about using LaunchDarkly with databases, see the
1825
* [SDK reference guide](https://docs.launchdarkly.com/v2.0/docs/using-a-persistent-feature-store).
@@ -22,10 +29,12 @@ class DynamoDb
2229
* - `dynamodb_options`: can include any settings supported by the AWS SDK client
2330
* - `dynamodb_prefix`: a string to be prepended to all database keys; corresponds to the prefix
2431
* setting in ld-relay
32+
* - `dynamodb_client`: an already-configured DynamoDb client instance if you wish to reuse one; if
33+
* specified, this will cause all other options except `dynamodb_prefix` and `dynamodb_table` to be ignored
2534
* - `apc_expiration`: expiration time in seconds for local caching, if `APCu` is installed
26-
* @return mixed an object to be stored in the `feature_requester` configuration property
35+
* @return \Closure an object to be stored in the `feature_requester` configuration property
2736
*/
28-
public static function featureRequester(array $options = array())
37+
public static function featureRequester(array $options = [])
2938
{
3039
return function ($baseUri, $sdkKey, $baseOptions) use ($options) {
3140
return new DynamoDbFeatureRequester($baseUri, $sdkKey, array_merge($baseOptions, $options));

0 commit comments

Comments
 (0)