diff --git a/src/LaunchDarkly/Impl/Integrations/DynamoDbFeatureRequester.php b/src/LaunchDarkly/Impl/Integrations/DynamoDbFeatureRequester.php index baefc23..9dc077a 100644 --- a/src/LaunchDarkly/Impl/Integrations/DynamoDbFeatureRequester.php +++ b/src/LaunchDarkly/Impl/Integrations/DynamoDbFeatureRequester.php @@ -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 . ':') : ''; diff --git a/src/LaunchDarkly/Integrations/DynamoDb.php b/src/LaunchDarkly/Integrations/DynamoDb.php index 8a436a0..4f4ddb1 100644 --- a/src/LaunchDarkly/Integrations/DynamoDb.php +++ b/src/LaunchDarkly/Integrations/DynamoDb.php @@ -1,7 +1,7 @@ "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). @@ -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));