Skip to content

Commit

Permalink
Refactor to use provider class
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjenkinson committed Oct 19, 2024
1 parent 124fa09 commit e74f0a2
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 189 deletions.
19 changes: 13 additions & 6 deletions src/Cache/DynamoDbCacheAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Rikudou\DynamoDbCache\DynamoDbCache;
use Rikudou\DynamoDbCache\Exception\InvalidArgumentException;
use Rikudou\DynamoDbCacheBundle\Converter\SymfonyCacheItemConverter;
use Rikudou\DynamoDbCacheBundle\Provider\DynamoDbCacheProvider;
use Symfony\Component\Cache\Adapter\AdapterInterface;
use Symfony\Component\Cache\CacheItem;
use Symfony\Contracts\Cache\CacheInterface;
Expand All @@ -16,14 +17,20 @@ final class DynamoDbCacheAdapter implements AdapterInterface, CacheInterface
{
use CacheTrait;

/**
* @param DynamoDbCache $cache
* @param SymfonyCacheItemConverter $converter
*/
private DynamoDbCache $cache;

private SymfonyCacheItemConverter $converter;

// @phpstan-ignore-next-line
private string $namespace;

public function __construct(
private DynamoDbCache $cache,
private SymfonyCacheItemConverter $converter
DynamoDbCacheProvider $provider,
string $namespace = '',
) {
$this->cache = $provider->cache;
$this->converter = $provider->converter;
$this->namespace = $namespace;
}

/**
Expand Down
15 changes: 15 additions & 0 deletions src/Provider/DynamoDbCacheProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Rikudou\DynamoDbCacheBundle\Provider;

use Rikudou\DynamoDbCache\DynamoDbCache;
use Rikudou\DynamoDbCacheBundle\Converter\SymfonyCacheItemConverter;

final class DynamoDbCacheProvider
{
public function __construct(
public DynamoDbCache $cache,
public SymfonyCacheItemConverter $converter
) {
}
}
1 change: 1 addition & 0 deletions src/Resources/config/aliases.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
services:
Rikudou\DynamoDbCacheBundle\Cache\DynamoDbCacheAdapter: '@rikudou.dynamo_cache.adapter'
Rikudou\DynamoDbCacheBundle\Provider\DynamoDbCacheProvider: '@rikudou.dynamo_cache.provider'
Rikudou\DynamoDbCache\DynamoDbCache: '@rikudou.dynamo_cache.cache'
Rikudou\DynamoDbCache\Encoder\CacheItemEncoderInterface: '@rikudou.dynamo_cache.encoder.default'
Rikudou\DynamoDbCacheBundle\Session\DynamoDbSessionHandler: '@rikudou.dynamo_cache.session'
10 changes: 8 additions & 2 deletions src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ services:
$converter: '@rikudou.dynamo_cache.converter_registry'
$encoder: '@rikudou.dynamo_cache.encoder.default'

rikudou.dynamo_cache.provider:
class: Rikudou\DynamoDbCacheBundle\Provider\DynamoDbCacheProvider
arguments:
$cache: '@rikudou.dynamo_cache.cache'
$converter: '@rikudou.dynamo_cache.converter.cache_item'

rikudou.dynamo_cache.adapter:
class: Rikudou\DynamoDbCacheBundle\Cache\DynamoDbCacheAdapter
arguments:
- '@rikudou.dynamo_cache.cache'
- '@rikudou.dynamo_cache.converter.cache_item'
- '@rikudou.dynamo_cache.provider'
- ''

rikudou.dynamo_cache.converter.cache_item:
class: Rikudou\DynamoDbCacheBundle\Converter\SymfonyCacheItemConverter
Expand Down
11 changes: 7 additions & 4 deletions tests/Cache/DynamoDbCacheAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Rikudou\DynamoDbCache\Encoder\SerializeItemEncoder;
use Rikudou\DynamoDbCacheBundle\Cache\DynamoDbCacheAdapter;
use Rikudou\DynamoDbCacheBundle\Converter\SymfonyCacheItemConverter;
use Rikudou\DynamoDbCacheBundle\Provider\DynamoDbCacheProvider;
use Rikudou\Tests\DynamoDbCacheBundle\AbstractDynamoDbTest;
use stdClass;
use Symfony\Component\Cache\CacheItem;
Expand All @@ -21,10 +22,12 @@ final class DynamoDbCacheAdapterTest extends AbstractDynamoDbTest
protected function setUp(): void
{
$this->instance = new DynamoDbCacheAdapter(
new DynamoDbCache('test', $this->getFakeDynamoDbClient($this->itemPoolDefault)),
new SymfonyCacheItemConverter(
new Clock(),
new SerializeItemEncoder()
new DynamoDbCacheProvider(
new DynamoDbCache('test', $this->getFakeDynamoDbClient($this->itemPoolDefault)),
new SymfonyCacheItemConverter(
new Clock(),
new SerializeItemEncoder()
)
)
);
}
Expand Down
Loading

0 comments on commit e74f0a2

Please sign in to comment.