Skip to content

Commit 34aa326

Browse files
Merge branch '6.x' into 8.x
2 parents c9cb36a + 74a79b2 commit 34aa326

File tree

4 files changed

+40
-23
lines changed

4 files changed

+40
-23
lines changed

src/Illuminate/Cache/CacheManager.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace Illuminate\Cache;
44

5+
use Aws\DynamoDb\DynamoDbClient;
56
use Closure;
67
use Illuminate\Contracts\Cache\Factory as FactoryContract;
78
use Illuminate\Contracts\Cache\Store;
89
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
10+
use Illuminate\Support\Arr;
911
use InvalidArgumentException;
1012

1113
/**
@@ -235,9 +237,11 @@ protected function createDatabaseDriver(array $config)
235237
*/
236238
protected function createDynamodbDriver(array $config)
237239
{
240+
$client = $this->newDynamodbClient($config);
241+
238242
return $this->repository(
239243
new DynamoDbStore(
240-
$this->app['cache.dynamodb.client'],
244+
$client,
241245
$config['table'],
242246
$config['attributes']['key'] ?? 'key',
243247
$config['attributes']['value'] ?? 'value',
@@ -247,6 +251,28 @@ protected function createDynamodbDriver(array $config)
247251
);
248252
}
249253

254+
/**
255+
* Create new DynamoDb Client instance.
256+
*
257+
* @return DynamoDbClient
258+
*/
259+
protected function newDynamodbClient(array $config)
260+
{
261+
$dynamoConfig = [
262+
'region' => $config['region'],
263+
'version' => 'latest',
264+
'endpoint' => $config['endpoint'] ?? null,
265+
];
266+
267+
if (isset($config['key']) && isset($config['secret'])) {
268+
$dynamoConfig['credentials'] = Arr::only(
269+
$config, ['key', 'secret', 'token']
270+
);
271+
}
272+
273+
return new DynamoDbClient($dynamoConfig);
274+
}
275+
250276
/**
251277
* Create a new cache repository with the given implementation.
252278
*

src/Illuminate/Cache/CacheServiceProvider.php

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Illuminate\Cache;
44

5-
use Aws\DynamoDb\DynamoDbClient;
65
use Illuminate\Contracts\Support\DeferrableProvider;
7-
use Illuminate\Support\Arr;
86
use Illuminate\Support\ServiceProvider;
97
use Symfony\Component\Cache\Adapter\Psr16Adapter;
108

@@ -33,24 +31,6 @@ public function register()
3331
return new MemcachedConnector;
3432
});
3533

36-
$this->app->singleton('cache.dynamodb.client', function ($app) {
37-
$config = $app['config']->get('cache.stores.dynamodb');
38-
39-
$dynamoConfig = [
40-
'region' => $config['region'],
41-
'version' => 'latest',
42-
'endpoint' => $config['endpoint'] ?? null,
43-
];
44-
45-
if ($config['key'] && $config['secret']) {
46-
$dynamoConfig['credentials'] = Arr::only(
47-
$config, ['key', 'secret', 'token']
48-
);
49-
}
50-
51-
return new DynamoDbClient($dynamoConfig);
52-
});
53-
5434
$this->app->singleton(RateLimiter::class);
5535
}
5636

@@ -62,7 +42,7 @@ public function register()
6242
public function provides()
6343
{
6444
return [
65-
'cache', 'cache.store', 'cache.psr6', 'memcached.connector', 'cache.dynamodb.client', RateLimiter::class,
45+
'cache', 'cache.store', 'cache.psr6', 'memcached.connector', RateLimiter::class,
6646
];
6747
}
6848
}

src/Illuminate/Cache/DynamoDbStore.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,4 +525,14 @@ public function setPrefix($prefix)
525525
{
526526
$this->prefix = ! empty($prefix) ? $prefix.':' : '';
527527
}
528+
529+
/**
530+
* Get the DynamoDb Client instance.
531+
*
532+
* @return DynamoDbClient
533+
*/
534+
public function getClient()
535+
{
536+
return $this->dynamo;
537+
}
528538
}

tests/Integration/Cache/DynamoDbStoreTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Aws\DynamoDb\DynamoDbClient;
66
use Aws\Exception\AwsException;
7+
use Illuminate\Contracts\Cache\Repository;
78
use Illuminate\Support\Facades\Cache;
89
use Illuminate\Support\Str;
910
use Orchestra\Testbench\TestCase;
@@ -85,7 +86,7 @@ protected function getEnvironmentSetUp($app)
8586
$config = $app['config']->get('cache.stores.dynamodb');
8687

8788
/** @var \Aws\DynamoDb\DynamoDbClient $client */
88-
$client = $app['cache.dynamodb.client'];
89+
$client = $app->make(Repository::class)->getStore()->getClient();
8990

9091
if ($this->dynamoTableExists($client, $config['table'])) {
9192
return;

0 commit comments

Comments
 (0)