From 4e33819eca94b774aaf9c43957d2e2586b1986db Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Sun, 4 Sep 2011 12:59:19 +0200 Subject: [PATCH] Added cache_type option for soap server definition --- DependencyInjection/BeSimpleSoapExtension.php | 4 +++ DependencyInjection/Configuration.php | 6 ++++ Resources/config/webservice.xml | 2 ++ Soap/SoapServerFactory.php | 36 ++++++++++++++++--- WebServiceContext.php | 5 ++- 5 files changed, 48 insertions(+), 5 deletions(-) diff --git a/DependencyInjection/BeSimpleSoapExtension.php b/DependencyInjection/BeSimpleSoapExtension.php index e14d6df..7625b57 100644 --- a/DependencyInjection/BeSimpleSoapExtension.php +++ b/DependencyInjection/BeSimpleSoapExtension.php @@ -106,6 +106,10 @@ class BeSimpleSoapExtension extends Extension $definition = new DefinitionDecorator('besimple.soap.context.'.$bindingSuffix); $context = $container->setDefinition($contextId, $definition); + if (isset($config['cache_type'])) { + $config['cache_type'] = $this->getCacheType($config['cache_type']); + } + $options = $container ->getDefinition('besimple.soap.context.'.$bindingSuffix) ->getArgument(4); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index a15bc22..cf95cc4 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -112,6 +112,12 @@ class Configuration ->thenInvalid("Service binding style has to be either 'rpc-literal' or 'document-wrapped'") ->end() ->end() + ->scalarNode('cache_type') + ->validate() + ->ifNotInArray($this->cacheTypes) + ->thenInvalid(sprintf('The cache type has to be either %s', implode(', ', $this->cacheTypes))) + ->end() + ->end() ->end() ->end() ->end() diff --git a/Resources/config/webservice.xml b/Resources/config/webservice.xml index 081e3b3..71adcfa 100644 --- a/Resources/config/webservice.xml +++ b/Resources/config/webservice.xml @@ -28,6 +28,7 @@ %besimple.soap.cache_dir% %kernel.debug% + null %besimple.soap.binder.request_header.rpcliteral.class% %besimple.soap.binder.request.rpcliteral.class% %besimple.soap.binder.response.rpcliteral.class% @@ -43,6 +44,7 @@ %besimple.soap.cache_dir% %kernel.debug% + null %besimple.soap.binder.request_header.documentwrapped.class% %besimple.soap.binder.request.documentwrapped.class% %besimple.soap.binder.response.documentwrapped.class% diff --git a/Soap/SoapServerFactory.php b/Soap/SoapServerFactory.php index eee5fd2..00d9204 100644 --- a/Soap/SoapServerFactory.php +++ b/Soap/SoapServerFactory.php @@ -22,14 +22,42 @@ class SoapServerFactory private $wsdlFile; private $classmap; private $converters; - private $debug; + private $options; - public function __construct($wsdlFile, array $classmap, ConverterRepository $converters, $debug = false) + public function __construct($wsdlFile, array $classmap, ConverterRepository $converters, array $options = array()) { $this->wsdlFile = $wsdlFile; $this->classmap = $this->fixSoapServerClassmap($classmap); $this->converters = $converters; - $this->debug = $debug; + $this->setOptions($options); + } + + public function setOptions(array $options) + { + $this->options = array( + 'debug' => false, + 'cache_type' => null, + ); + + // check option names and live merge, if errors are encountered Exception will be thrown + $invalid = array(); + $isInvalid = false; + foreach ($options as $key => $value) { + if (array_key_exists($key, $this->options)) { + $this->options[$key] = $value; + } else { + $isInvalid = true; + $invalid[] = $key; + } + } + + if ($isInvalid) { + throw new \InvalidArgumentException(sprintf( + 'The "%s" class does not support the following options: "%s".', + get_class($this), + implode('\', \'', $invalid) + )); + } } public function create($request, $response) @@ -40,7 +68,7 @@ class SoapServerFactory 'classmap' => $this->classmap, 'typemap' => $this->createSoapServerTypemap($request, $response), 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, - 'cache_wsdl' => Cache::getType(), + 'cache_wsdl' => null !== $this->options['cache_type'] ? $this->options['cache_type'] : Cache::getType(), ) ); } diff --git a/WebServiceContext.php b/WebServiceContext.php index ccf1ad9..a5d4e4a 100644 --- a/WebServiceContext.php +++ b/WebServiceContext.php @@ -103,7 +103,10 @@ class WebServiceContext $this->getWsdlFile(), $this->serviceDefinition->getDefinitionComplexTypes(), $this->converterRepository, - $this->options['debug'] + array( + 'debug' => $this->options['debug'], + 'cache_type' => isset($this->options['cache_type']) ? $this->options['cache_type'] : null, + ) ); }