Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public function __construct(string $baseUri, string $sdkKey, array $options)

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

$prefix = $options['dynamodb_prefix'] ?? '';
$this->_prefix = ($prefix != null && $prefix != '') ? ($prefix . ':') : '';
Expand Down
21 changes: 15 additions & 6 deletions src/LaunchDarkly/Integrations/DynamoDb.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace LaunchDarkly\Integrations;

use \LaunchDarkly\Impl\Integrations\DynamoDbFeatureRequester;
use LaunchDarkly\Impl\Integrations\DynamoDbFeatureRequester;

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