diff --git a/DependencyInjection/Factory/CacheAdapterFactory.php b/DependencyInjection/Factory/CacheAdapterFactory.php new file mode 100644 index 0000000..aa9573e --- /dev/null +++ b/DependencyInjection/Factory/CacheAdapterFactory.php @@ -0,0 +1,53 @@ + + */ +class CacheAdapterFactory implements AdapterFactoryInterface +{ + /** + * {@inheritDoc} + */ + public function create(ContainerBuilder $container, $id, array $config) + { + $container + ->setDefinition($id, new DefinitionDecorator('knp_gaufrette.adapter.cache')) + ->addArgument(new Reference('gaufrette.' . $config['source'] . '_adapter')) + ->addArgument(new Reference('gaufrette.' . $config['cache'] . '_adapter')) + ->addArgument($config['ttl']) + ->addArgument($config['serialize'] ? new Reference('gaufrette.' . $config['serialize'] . '_adapter') : null) + ; + } + + /** + * {@inheritDoc} + */ + public function getKey() + { + return 'cache'; + } + + /** + * {@inheritDoc} + */ + public function addConfiguration(NodeDefinition $node) + { + $node + ->children() + ->scalarNode('source')->isRequired()->cannotBeEmpty()->end() + ->scalarNode('cache')->isRequired()->cannotBeEmpty()->end() + ->scalarNode('ttl')->defaultValue(0)->end() + ->scalarNode('serialize')->defaultNull()->end() + ->end() + ; + } +} diff --git a/Resources/config/adapter_factories.xml b/Resources/config/adapter_factories.xml index 6adc9b2..4d52403 100644 --- a/Resources/config/adapter_factories.xml +++ b/Resources/config/adapter_factories.xml @@ -35,6 +35,9 @@ + + + diff --git a/Resources/config/gaufrette.xml b/Resources/config/gaufrette.xml index 5fbdde6..db8720d 100644 --- a/Resources/config/gaufrette.xml +++ b/Resources/config/gaufrette.xml @@ -34,6 +34,7 @@ +