Added the possibility to choice an other type cache for a client

This commit is contained in:
Francis Besset 2011-09-04 02:42:53 +02:00
parent 1a4e9246db
commit 2ea1704a1e
3 changed files with 41 additions and 19 deletions

View File

@ -67,23 +67,7 @@ class BeSimpleSoapExtension extends Extension
{ {
$loader->load('soap.xml'); $loader->load('soap.xml');
switch ($config['type']) { $config['type'] = $this->getCacheType($config['type']);
case 'none':
$config['type'] = Cache::TYPE_NONE;
break;
case 'disk':
$config['type'] = Cache::TYPE_DISK;
break;
case 'memory':
$config['type'] = Cache::TYPE_MEMORY;
break;
case 'disk_memory':
$config['type'] = Cache::TYPE_DISK_MEMORY;
break;
}
foreach (array('type', 'lifetime', 'limit') as $key) { foreach (array('type', 'lifetime', 'limit') as $key) {
$container->setParameter('besimple.soap.cache.'.$key, $config[$key]); $container->setParameter('besimple.soap.cache.'.$key, $config[$key]);
@ -99,6 +83,17 @@ class BeSimpleSoapExtension extends Extension
$context = $container->setDefinition(sprintf('besimple.soap.client.%s', $client), $definition); $context = $container->setDefinition(sprintf('besimple.soap.client.%s', $client), $definition);
$definition->replaceArgument(0, $options['wsdl']); $definition->replaceArgument(0, $options['wsdl']);
if (isset($options['cache_wsdl'])) {
$options['cache_wsdl'] = $this->getCacheType($options['cache_wsdl']);
$defOptions = $container
->getDefinition('besimple.soap.client')
->getArgument(1);
$defOptions['cache_wsdl'] = $options['cache_wsdl'];
$definition->replaceArgument(1, $defOptions);
}
} }
} }
@ -117,4 +112,21 @@ class BeSimpleSoapExtension extends Extension
$definition->replaceArgument(4, array_merge($options, $config)); $definition->replaceArgument(4, array_merge($options, $config));
} }
private function getCacheType($type)
{
switch ($type) {
case 'none':
return Cache::TYPE_NONE;
case 'disk':
return Cache::TYPE_DISK;
case 'memory':
return Cache::TYPE_MEMORY;
case 'disk_memory':
return Cache::TYPE_DISK_MEMORY;
}
}
} }

View File

@ -23,6 +23,8 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder;
*/ */
class Configuration class Configuration
{ {
private $cacheTypes = array('none', 'disk', 'memory', 'disk_memory');
/** /**
* Generates the configuration tree. * Generates the configuration tree.
* *
@ -46,12 +48,13 @@ class Configuration
$rootNode $rootNode
->children() ->children()
->arrayNode('cache') ->arrayNode('cache')
->addDefaultsIfNotSet()
->children() ->children()
->scalarNode('type') ->scalarNode('type')
->defaultValue('disk') ->defaultValue('disk')
->validate() ->validate()
->ifNotInArray(array('none', 'disk', 'memory', 'disk_memory')) ->ifNotInArray($this->cacheTypes)
->thenInvalid('The cache type has to be either "none", "disk", "memory" or "disk_memory"') ->thenInvalid(sprintf('The cache type has to be either %s', implode(', ', $this->cacheTypes)))
->end() ->end()
->end() ->end()
->scalarNode('lifetime')->defaultNull()->end() ->scalarNode('lifetime')->defaultNull()->end()
@ -73,6 +76,12 @@ class Configuration
->scalarNode('wsdl') ->scalarNode('wsdl')
->isRequired() ->isRequired()
->end() ->end()
->scalarNode('cache_wsdl')
->validate()
->ifNotInArray($this->cacheTypes)
->thenInvalid(sprintf('The cache type has to be either %s', implode(', ', $this->cacheTypes)))
->end()
->end()
->end() ->end()
->end() ->end()
->end() ->end()

View File

@ -12,6 +12,7 @@
<argument>wsdl</argument> <argument>wsdl</argument>
<argument type="collection"> <argument type="collection">
<argument key="debug">%kernel.debug%</argument> <argument key="debug">%kernel.debug%</argument>
<argument key="cache_wsdl">null</argument>
</argument> </argument>
<argument type="service" id="besimple.soap.cache" /> <argument type="service" id="besimple.soap.cache" />
</service> </service>