Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to use provider class #33

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading