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="collection">
<argument key="cache_dir">%webservice.cache_dir%</argument>
<argument key="debug">%kernel.debug%</argument>
</argument>
</service>

View File

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

View File

@ -95,7 +95,7 @@ class WebServiceContext
public function getServerFactory()
{
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;