CacheAdapterFactory created

This commit is contained in:
Robin van der Vleuten 2012-03-01 17:13:11 +01:00
parent b414f4f142
commit d547add078
3 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,51 @@
<?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()
;
}
}

View File

@ -35,6 +35,9 @@
<service id="knp_gaufrette.adapter.factory.apc" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\ApcAdapterFactory"> <service id="knp_gaufrette.adapter.factory.apc" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\ApcAdapterFactory">
<tag name="gaufrette.adapter.factory" /> <tag name="gaufrette.adapter.factory" />
</service> </service>
<service id="knp_gaufrette.adapter.factory.cache" class="Knp\Bundle\GaufretteBundle\DependencyInjection\Factory\CacheAdapterFactory">
<tag name="gaufrette.adapter.factory" />
</service>
</services> </services>

View File

@ -31,6 +31,7 @@
<argument /><!-- prefix --> <argument /><!-- prefix -->
<argument /><!-- ttl --> <argument /><!-- ttl -->
</service> </service>
<service id="knp_gaufrette.adapter.cache" class="Gaufrette\Adapter\Cache" abstract="true" public="false" />
<service id="knp_gaufrette.filesystem_map" class="Knp\Bundle\GaufretteBundle\FilesystemMap"> <service id="knp_gaufrette.filesystem_map" class="Knp\Bundle\GaufretteBundle\FilesystemMap">
<argument /> <!-- map of filesystems --> <argument /> <!-- map of filesystems -->
</service> </service>