52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
|
<?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)
|
||
|
{
|
||
|
$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'])
|
||
|
;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* {@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()
|
||
|
->end()
|
||
|
;
|
||
|
}
|
||
|
}
|