DynamoDbClient.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace Aws\DynamoDb;
  3. use Aws\Api\Parser\Crc32ValidatingParser;
  4. use Aws\AwsClient;
  5. use Aws\ClientResolver;
  6. use Aws\HandlerList;
  7. use Aws\Middleware;
  8. use Aws\RetryMiddleware;
  9. /**
  10. * This client is used to interact with the **Amazon DynamoDB** service.
  11. *
  12. * @method \Aws\Result batchGetItem(array $args = [])
  13. * @method \GuzzleHttp\Promise\Promise batchGetItemAsync(array $args = [])
  14. * @method \Aws\Result batchWriteItem(array $args = [])
  15. * @method \GuzzleHttp\Promise\Promise batchWriteItemAsync(array $args = [])
  16. * @method \Aws\Result createTable(array $args = [])
  17. * @method \GuzzleHttp\Promise\Promise createTableAsync(array $args = [])
  18. * @method \Aws\Result deleteItem(array $args = [])
  19. * @method \GuzzleHttp\Promise\Promise deleteItemAsync(array $args = [])
  20. * @method \Aws\Result deleteTable(array $args = [])
  21. * @method \GuzzleHttp\Promise\Promise deleteTableAsync(array $args = [])
  22. * @method \Aws\Result describeTable(array $args = [])
  23. * @method \GuzzleHttp\Promise\Promise describeTableAsync(array $args = [])
  24. * @method \Aws\Result getItem(array $args = [])
  25. * @method \GuzzleHttp\Promise\Promise getItemAsync(array $args = [])
  26. * @method \Aws\Result listTables(array $args = [])
  27. * @method \GuzzleHttp\Promise\Promise listTablesAsync(array $args = [])
  28. * @method \Aws\Result putItem(array $args = [])
  29. * @method \GuzzleHttp\Promise\Promise putItemAsync(array $args = [])
  30. * @method \Aws\Result query(array $args = [])
  31. * @method \GuzzleHttp\Promise\Promise queryAsync(array $args = [])
  32. * @method \Aws\Result scan(array $args = [])
  33. * @method \GuzzleHttp\Promise\Promise scanAsync(array $args = [])
  34. * @method \Aws\Result updateItem(array $args = [])
  35. * @method \GuzzleHttp\Promise\Promise updateItemAsync(array $args = [])
  36. * @method \Aws\Result updateTable(array $args = [])
  37. * @method \GuzzleHttp\Promise\Promise updateTableAsync(array $args = [])
  38. * @method \Aws\Result describeLimits(array $args = []) (supported in versions 2012-08-10)
  39. * @method \GuzzleHttp\Promise\Promise describeLimitsAsync(array $args = []) (supported in versions 2012-08-10)
  40. * @method \Aws\Result describeTimeToLive(array $args = []) (supported in versions 2012-08-10)
  41. * @method \GuzzleHttp\Promise\Promise describeTimeToLiveAsync(array $args = []) (supported in versions 2012-08-10)
  42. * @method \Aws\Result listTagsOfResource(array $args = []) (supported in versions 2012-08-10)
  43. * @method \GuzzleHttp\Promise\Promise listTagsOfResourceAsync(array $args = []) (supported in versions 2012-08-10)
  44. * @method \Aws\Result tagResource(array $args = []) (supported in versions 2012-08-10)
  45. * @method \GuzzleHttp\Promise\Promise tagResourceAsync(array $args = []) (supported in versions 2012-08-10)
  46. * @method \Aws\Result untagResource(array $args = []) (supported in versions 2012-08-10)
  47. * @method \GuzzleHttp\Promise\Promise untagResourceAsync(array $args = []) (supported in versions 2012-08-10)
  48. * @method \Aws\Result updateTimeToLive(array $args = []) (supported in versions 2012-08-10)
  49. * @method \GuzzleHttp\Promise\Promise updateTimeToLiveAsync(array $args = []) (supported in versions 2012-08-10)
  50. */
  51. class DynamoDbClient extends AwsClient
  52. {
  53. public static function getArguments()
  54. {
  55. $args = parent::getArguments();
  56. $args['retries']['default'] = 10;
  57. $args['retries']['fn'] = [__CLASS__, '_applyRetryConfig'];
  58. $args['api_provider']['fn'] = [__CLASS__, '_applyApiProvider'];
  59. return $args;
  60. }
  61. /**
  62. * Convenience method for instantiating and registering the DynamoDB
  63. * Session handler with this DynamoDB client object.
  64. *
  65. * @param array $config Array of options for the session handler factory
  66. *
  67. * @return SessionHandler
  68. */
  69. public function registerSessionHandler(array $config = [])
  70. {
  71. $handler = SessionHandler::fromClient($this, $config);
  72. $handler->register();
  73. return $handler;
  74. }
  75. /** @internal */
  76. public static function _applyRetryConfig($value, array &$args, HandlerList $list)
  77. {
  78. if (!$value) {
  79. return;
  80. }
  81. $list->appendSign(
  82. Middleware::retry(
  83. RetryMiddleware::createDefaultDecider($value),
  84. function ($retries) {
  85. return $retries
  86. ? RetryMiddleware::exponentialDelay($retries) / 2
  87. : 0;
  88. },
  89. isset($args['stats']['retries'])
  90. ? (bool) $args['stats']['retries']
  91. : false
  92. ),
  93. 'retry'
  94. );
  95. }
  96. /** @internal */
  97. public static function _applyApiProvider($value, array &$args, HandlerList $list)
  98. {
  99. ClientResolver::_apply_api_provider($value, $args, $list);
  100. $args['parser'] = new Crc32ValidatingParser($args['parser']);
  101. }
  102. }