Added debug parameter at SoapServerFactory

If kernel.debug parameter is true, the cache is disabled.
This commit is contained in:
Francis Besset 2011-07-17 12:35:47 +02:00
parent 1c608ccf20
commit 887169de13
3 changed files with 17 additions and 15 deletions

View File

@ -24,6 +24,7 @@
<argument type="service" id="webservice.binder.response"/> <argument type="service" id="webservice.binder.response"/>
<argument type="collection"> <argument type="collection">
<argument key="cache_dir">%webservice.cache_dir%</argument> <argument key="cache_dir">%webservice.cache_dir%</argument>
<argument key="debug">%kernel.debug%</argument>
</argument> </argument>
</service> </service>

View File

@ -23,34 +23,35 @@ class SoapServerFactory
private $definition; private $definition;
private $converters; private $converters;
private $wsdlFile; private $wsdlFile;
private $debug;
public function __construct(ServiceDefinition $definition, $wsdlFile, ConverterRepository $converters) public function __construct(ServiceDefinition $definition, $wsdlFile, ConverterRepository $converters, $debug = false)
{ {
$this->definition = $definition; $this->definition = $definition;
$this->wsdlFile = $wsdlFile; $this->wsdlFile = $wsdlFile;
$this->converters = $converters; $this->converters = $converters;
$this->debug = $debug;
} }
public function create($request, $response) public function create($request, $response)
{ {
$server = new \SoapServer( return new \SoapServer(
$this->wsdlFile, $this->wsdlFile,
array( array(
'classmap' => $this->createSoapServerClassmap(), 'classmap' => $this->createSoapServerClassmap(),
'typemap' => $this->createSoapServerTypemap($request, $response), 'typemap' => $this->createSoapServerTypemap($request, $response),
'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
'cache_wsdl' => $this->debug ? WSDL_CACHE_NONE : WSDL_CACHE_DISK,
) )
); );
return $server;
} }
private function createSoapServerTypemap($request, $response) private function createSoapServerTypemap($request, $response)
{ {
$result = array(); $typemap = array();
foreach($this->converters->getTypeConverters() as $typeConverter) { foreach($this->converters->getTypeConverters() as $typeConverter) {
$result[] = array( $typemap[] = array(
'type_name' => $typeConverter->getTypeName(), 'type_name' => $typeConverter->getTypeName(),
'type_ns' => $typeConverter->getTypeNamespace(), 'type_ns' => $typeConverter->getTypeNamespace(),
'from_xml' => function($input) use ($request, $typeConverter) { 'from_xml' => function($input) use ($request, $typeConverter) {
@ -62,24 +63,24 @@ class SoapServerFactory
); );
} }
return $result; return $typemap;
} }
private function createSoapServerClassmap() private function createSoapServerClassmap()
{ {
$result = array(); $classmap = array();
foreach($this->definition->getHeaders() as $header) { foreach($this->definition->getHeaders() as $header) {
$this->addSoapServerClassmapEntry($result, $header->getType()); $this->addSoapServerClassmapEntry($classmap, $header->getType());
} }
foreach($this->definition->getMethods() as $method) { foreach($this->definition->getMethods() as $method) {
foreach($method->getArguments() as $arg) { foreach($method->getArguments() as $arg) {
$this->addSoapServerClassmapEntry($result, $arg->getType()); $this->addSoapServerClassmapEntry($classmap, $arg->getType());
} }
} }
return $result; return $classmap;
} }
private function addSoapServerClassmapEntry(&$classmap, Type $type) private function addSoapServerClassmapEntry(&$classmap, Type $type)

View File

@ -95,7 +95,7 @@ class WebServiceContext
public function getServerFactory() public function getServerFactory()
{ {
if (null === $this->serverFactory) { if (null === $this->serverFactory) {
$this->serverFactory = new SoapServerFactory($this->getServiceDefinition(), $this->getWsdlFile(), $this->converterRepository); $this->serverFactory = new SoapServerFactory($this->getServiceDefinition(), $this->getWsdlFile(), $this->converterRepository, $this->options['debug']);
} }
return $this->serverFactory; return $this->serverFactory;