Skip to content

Commit

Permalink
Add debug support
Browse files Browse the repository at this point in the history
Close #72
  • Loading branch information
baopham committed Aug 12, 2017
1 parent 2079caa commit 2acdcb4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Install
'region' => env('DYNAMODB_REGION'),
'local_endpoint' => env('DYNAMODB_LOCAL_ENDPOINT'), // see http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Tools.DynamoDBLocal.html
'local' => env('DYNAMODB_LOCAL'), // true or false? should use dynamodb_local or not?
'debug' => true, // if true, it will use Laravel Log. For advanced options, see http://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/configuration.html
],
...
```
Expand All @@ -61,12 +62,8 @@ Install
// config/services.php
...
'dynamodb' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
...
'token' => env('AWS_SESSION_TOKEN'),
'region'=> env('DYNAMODB_REGION'),
'local_endpoint' => env('DYNAMODB_LOCAL_ENDPOINT'),
'local'=> env('DYNAMODB_LOCAL') // true or false? should use dynamodb_local or not?
]
...
```
Expand Down
19 changes: 19 additions & 0 deletions src/DynamoDbServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Aws\DynamoDb\Marshaler;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;

class DynamoDbServiceProvider extends ServiceProvider
Expand Down Expand Up @@ -34,6 +35,21 @@ public function register()
$this->bindForApp($marshalerOptions);
}

protected function getDebugOptions()
{
$debug = config('services.dynamodb.debug');

if ($debug === true) {
$logfn = function ($msg) {
Log::info($msg);
};

return ['logfn' => $logfn];
}

return $debug;
}

protected function bindForApp($marshalerOptions = [])
{
$this->app->singleton('BaoPham\DynamoDb\DynamoDbClientInterface', function ($app) use ($marshalerOptions) {
Expand All @@ -45,6 +61,7 @@ protected function bindForApp($marshalerOptions = [])
],
'region' => config('services.dynamodb.region'),
'version' => '2012-08-10',
'debug' => $this->getDebugOptions(),
];

$client = new DynamoDbClientService($config, new Marshaler($marshalerOptions), new EmptyAttributeFilter());
Expand All @@ -66,7 +83,9 @@ protected function bindForTesting($marshalerOptions = [])
'region' => $region,
'version' => '2012-08-10',
'endpoint' => config('services.dynamodb.local_endpoint'),
'debug' => $this->getDebugOptions(),
];

$client = new DynamoDbClientService($config, new Marshaler($marshalerOptions), new EmptyAttributeFilter());

return $client;
Expand Down

0 comments on commit 2acdcb4

Please sign in to comment.