KnpGaufretteBundle/DependencyInjection/Factory/CacheAdapterFactory.php

54 lines
1.6 KiB
PHP
Raw Permalink Normal View History

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)
{
$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'])
->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()
->scalarNode('serialize')->defaultNull()->end()
2012-03-01 16:13:11 +00:00
->end()
;
}
}