Skip to content

Commit

Permalink
Feat: Add base64 encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage committed Apr 27, 2023
1 parent f94a337 commit 94e60c2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": "MIT",
"require": {
"symfony/framework-bundle": "^6.0",
"rikudou/psr6-dynamo-db": "^3.0",
"rikudou/psr6-dynamo-db": "^3.1",
"php": "^8.0",
"symfony/cache": "^6.0",
"ext-json": "*"
Expand Down
4 changes: 4 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public function getConfigTreeBuilder(): TreeBuilder
->info('The service to be used as the encoder/decoder')
->defaultValue('rikudou.dynamo_cache.encoder.serialize')
->end()
->scalarNode('base64_decorated_service')
->info('The service that is decorated by base64 item encoder. Must be a service implementing CacheItemEncoderInterface. Ignored if the encoder is not set to rikudou.dynamo_cache.encoder.base64.')
->defaultValue('rikudou.dynamo_cache.encoder.serialize')
->end()
->arrayNode('json_options')
->info('Settings for the json encoder')
->addDefaultsIfNotSet()
Expand Down
6 changes: 6 additions & 0 deletions src/DependencyInjection/RikudouDynamoDbCacheExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ private function createDefaultEncoder(ContainerBuilder $container, array $config

$container->removeDefinition('rikudou.dynamo_cache.encoder.default');
$container->setAlias('rikudou.dynamo_cache.encoder.default', $configs['encoder']['service']);

if ($configs['encoder']['service'] === 'rikudou.dynamo_cache.encoder.base64') {
$definition = $container->getDefinition($configs['encoder']['service']);
$decoratedService = $configs['encoder']['base64_decorated_service'];
$definition->setArgument(0, new Reference($decoratedService));
}
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ services:
- '%rikudou.dynamo_cache.json_encoder.decode_flags%'
- '%rikudou.dynamo_cache.json_encoder.depth%'

rikudou.dynamo_cache.encoder.base64:
class: Rikudou\DynamoDbCache\Encoder\Base64ItemEncoder
arguments:
- '@rikudou.dynamo_cache.encoder.serialize' # redefined in extension

rikudou.dynamo_cache.encoder.default: '@rikudou.dynamo_cache.encoder.serialize' # redefined in extension

rikudou.dynamo_cache.cache: # arguments defined in extension
Expand Down

0 comments on commit 94e60c2

Please sign in to comment.