diff --git a/Cache.php b/Cache.php new file mode 100644 index 0000000..71d8927 --- /dev/null +++ b/Cache.php @@ -0,0 +1,39 @@ + + * (c) Francis Besset + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace BeSimple\SoapBundle; + +use BeSimple\SoapCommon\Cache as BaseCache; + +/** + * @author Francis Besset + */ +class Cache +{ + public function __construct($disabled, $type, $directory, $lifetime = null, $limit = null) + { + BaseCache::setEnabled(!$disabled); + + if (BaseCache::ENABLED == BaseCache::isEnabled()) { + BaseCache::setType($type); + BaseCache::setDirectory($directory); + + if (null !== $lifetime) { + BaseCache::setLifetime($lifetime); + } + + if (null !== $limit) { + BaseCache::setLimit($limit); + } + } + } +} \ No newline at end of file diff --git a/DependencyInjection/BeSimpleSoapExtension.php b/DependencyInjection/BeSimpleSoapExtension.php index 9b492b7..5abd6de 100644 --- a/DependencyInjection/BeSimpleSoapExtension.php +++ b/DependencyInjection/BeSimpleSoapExtension.php @@ -1,8 +1,10 @@ + * (c) Francis Besset * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. @@ -10,6 +12,8 @@ namespace BeSimple\SoapBundle\DependencyInjection; +use BeSimple\SoapCommon\Cache; + use Symfony\Component\Config\Definition\Processor; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -22,6 +26,7 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension; * BeSimpleSoapExtension. * * @author Christian Kerl + * @author Francis Besset */ class BeSimpleSoapExtension extends Extension { @@ -44,6 +49,8 @@ class BeSimpleSoapExtension extends Extension $config = $processor->process($configuration->getConfigTree(), $configs); + $this->registerCacheConfiguration($config['cache'], $container, $loader); + if (isset($config['clients'])) { $this->registerClientConfiguration($config['clients'], $container, $loader); } @@ -56,6 +63,33 @@ class BeSimpleSoapExtension extends Extension } } + private function registerCacheConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader) + { + $loader->load('soap.xml'); + + switch ($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) { + $container->setParameter('besimple.soap.cache.'.$key, $config[$key]); + } + } + private function registerClientConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader) { $loader->load('client.xml'); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 2228f37..dde299d 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -1,8 +1,10 @@ + * (c) Francis Besset * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. @@ -17,6 +19,7 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder; * WebServiceExtension configuration structure. * * @author Christian Kerl + * @author Francis Besset */ class Configuration { @@ -30,6 +33,7 @@ class Configuration $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('be_simple_soap'); + $this->addCacheSection($rootNode); $this->addClientSection($rootNode); $this->addServicesSection($rootNode); $this->addWsdlDumperSection($rootNode); @@ -37,6 +41,27 @@ class Configuration return $treeBuilder->buildTree(); } + private function addCacheSection(ArrayNodeDefinition $rootNode) + { + $rootNode + ->children() + ->arrayNode('cache') + ->children() + ->scalarNode('type') + ->defaultValue('disk') + ->validate() + ->ifNotInArray(array('none', 'disk', 'memory', 'disk_memory')) + ->thenInvalid('The cache type has to be either "none", "disk", "memory" or "disk_memory"') + ->end() + ->end() + ->scalarNode('lifetime')->defaultNull()->end() + ->scalarNode('limit')->defaultNull()->end() + ->end() + ->end() + ->end() + ; + } + private function addClientSection(ArrayNodeDefinition $rootNode) { $rootNode diff --git a/Resources/config/client.xml b/Resources/config/client.xml index 405a4de..7869c80 100644 --- a/Resources/config/client.xml +++ b/Resources/config/client.xml @@ -13,6 +13,7 @@ %kernel.debug% + diff --git a/Resources/config/soap.xml b/Resources/config/soap.xml new file mode 100644 index 0000000..3fb3d4c --- /dev/null +++ b/Resources/config/soap.xml @@ -0,0 +1,21 @@ + + + + + BeSimple\SoapBundle\Cache + %kernel.cache_dir%/besimple/soap + + + + + %kernel.debug% + %besimple.soap.cache.type% + %besimple.soap.cache.directory% + %besimple.soap.cache.lifetime% + %besimple.soap.cache.limit% + + + + diff --git a/Resources/config/webservice.xml b/Resources/config/webservice.xml index a33b0c2..081e3b3 100644 --- a/Resources/config/webservice.xml +++ b/Resources/config/webservice.xml @@ -32,6 +32,7 @@ %besimple.soap.binder.request.rpcliteral.class% %besimple.soap.binder.response.rpcliteral.class% + @@ -46,6 +47,7 @@ %besimple.soap.binder.request.documentwrapped.class% %besimple.soap.binder.response.documentwrapped.class% + diff --git a/Soap/SoapServerFactory.php b/Soap/SoapServerFactory.php index 1e18767..eee5fd2 100644 --- a/Soap/SoapServerFactory.php +++ b/Soap/SoapServerFactory.php @@ -11,6 +11,7 @@ namespace BeSimple\SoapBundle\Soap; use BeSimple\SoapBundle\Converter\ConverterRepository; +use BeSimple\SoapCommon\Cache; use Zend\Soap\Wsdl; /** @@ -39,7 +40,7 @@ class SoapServerFactory 'classmap' => $this->classmap, 'typemap' => $this->createSoapServerTypemap($request, $response), 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, - 'cache_wsdl' => $this->debug ? WSDL_CACHE_NONE : WSDL_CACHE_DISK, + 'cache_wsdl' => Cache::getType(), ) ); }