2012-03-01 16:13:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Knp\Bundle\GaufretteBundle\DependencyInjection\Factory;
|
|
|
|
|
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
|
|
|
use Symfony\Component\DependencyInjection\Reference;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cache adapter factory
|
|
|
|
*
|
|
|
|
* @author Robin van der Vleuten <robinvdvleuten@gmail.com>
|
|
|
|
*/
|
|
|
|
class CacheAdapterFactory implements AdapterFactoryInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function create(ContainerBuilder $container, $id, array $config)
|
|
|
|
{
|
2012-09-05 17:45:48 +00:00
|
|
|
$container
|
2012-03-01 16:13:11 +00:00
|
|
|
->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'])
|
2012-03-01 16:35:36 +00:00
|
|
|
->addArgument($config['serialize'] ? new Reference('gaufrette.' . $config['serialize'] . '_adapter') : null)
|
2012-03-01 16:13:11 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@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()
|
2012-03-01 16:35:36 +00:00
|
|
|
->scalarNode('serialize')->defaultNull()->end()
|
2012-03-01 16:13:11 +00:00
|
|
|
->end()
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|