Skip to content

Commit e7e9d7b

Browse files
committed
Refactor service provider
1 parent 27b1274 commit e7e9d7b

File tree

1 file changed

+41
-31
lines changed

1 file changed

+41
-31
lines changed

src/DynamoDbServiceProvider.php

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,47 @@ public function register()
1717
'nullify_invalid' => true,
1818
];
1919

20-
if (App::environment() == 'testing' || config('services.dynamodb.local')) {
21-
$this->app->singleton('BaoPham\DynamoDb\DynamoDbClientInterface', function ($app) use ($marshalerOptions) {
22-
$region = App::environment() == 'testing' ? 'test' : 'stub';
23-
24-
$config = [
25-
'credentials' => [
26-
'key' => 'dynamodb_local',
27-
'secret' => 'secret',
28-
],
29-
'region' => $region,
30-
'version' => '2012-08-10',
31-
'endpoint' => config('services.dynamodb.local_endpoint'),
32-
];
33-
$client = new DynamoDbClientService($config, new Marshaler($marshalerOptions), new EmptyAttributeFilter());
34-
35-
return $client;
36-
});
37-
} else {
38-
$this->app->singleton('BaoPham\DynamoDb\DynamoDbClientInterface', function ($app) use ($marshalerOptions) {
39-
$config = [
40-
'credentials' => [
41-
'key' => config('services.dynamodb.key'),
42-
'secret' => config('services.dynamodb.secret'),
43-
],
44-
'region' => config('services.dynamodb.region'),
45-
'version' => '2012-08-10',
46-
];
47-
$client = new DynamoDbClientService($config, new Marshaler($marshalerOptions), new EmptyAttributeFilter());
48-
49-
return $client;
50-
});
20+
if ($this->app->environment() == 'testing' || config('services.dynamodb.local')) {
21+
return $this->bindForTesting($marshalerOptions);
5122
}
23+
24+
$this->bindForApp($marshalerOptions);
25+
}
26+
27+
protected function bindForApp($marshalerOptions = [])
28+
{
29+
$this->app->singleton('BaoPham\DynamoDb\DynamoDbClientInterface', function ($app) use ($marshalerOptions) {
30+
$config = [
31+
'credentials' => [
32+
'key' => config('services.dynamodb.key'),
33+
'secret' => config('services.dynamodb.secret'),
34+
],
35+
'region' => config('services.dynamodb.region'),
36+
'version' => '2012-08-10',
37+
];
38+
$client = new DynamoDbClientService($config, new Marshaler($marshalerOptions), new EmptyAttributeFilter());
39+
40+
return $client;
41+
});
42+
}
43+
44+
protected function bindForTesting($marshalerOptions = [])
45+
{
46+
$this->app->singleton('BaoPham\DynamoDb\DynamoDbClientInterface', function ($app) use ($marshalerOptions) {
47+
$region = App::environment() == 'testing' ? 'test' : 'stub';
48+
49+
$config = [
50+
'credentials' => [
51+
'key' => 'dynamodb_local',
52+
'secret' => 'secret',
53+
],
54+
'region' => $region,
55+
'version' => '2012-08-10',
56+
'endpoint' => config('services.dynamodb.local_endpoint'),
57+
];
58+
$client = new DynamoDbClientService($config, new Marshaler($marshalerOptions), new EmptyAttributeFilter());
59+
60+
return $client;
61+
});
5262
}
5363
}

0 commit comments

Comments
 (0)