Deleted SoapServerFactory and used BeSimple\SoapServer\SoapServerBuilder to build the SoapServer

This commit is contained in:
Francis Besset 2011-10-12 22:01:50 +02:00
parent 70a85460c9
commit 32259355d6
3 changed files with 21 additions and 95 deletions

View File

@ -58,9 +58,11 @@ class SoapWebServiceController extends ContainerAware
$this->serviceBinder = $webServiceContext->getServiceBinder(); $this->serviceBinder = $webServiceContext->getServiceBinder();
$this->soapRequest = SoapRequest::createFromHttpRequest($this->container->get('request')); $this->soapRequest = SoapRequest::createFromHttpRequest($this->container->get('request'));
$this->soapServer = $webServiceContext->getServerFactory()->create($this->soapRequest, $this->getResponse()); $this->soapServer = $webServiceContext
->getServerBuilder()
$this->soapServer->setObject($this); ->withHandler($this)
->build()
;
ob_start(); ob_start();
$this->soapServer->handle($this->soapRequest->getSoapMessage()); $this->soapServer->handle($this->soapRequest->getSoapMessage());

View File

@ -1,78 +0,0 @@
<?php
/*
* This file is part of the BeSimpleSoapBundle.
*
* (c) Christian Kerl <christian-kerl@web.de>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace BeSimple\SoapBundle\Soap;
use BeSimple\SoapCommon\Cache;
use BeSimple\SoapCommon\Classmap;
use BeSimple\SoapCommon\Converter\TypeConverterCollection;
use Zend\Soap\Wsdl;
/**
* @author Christian Kerl <christian-kerl@web.de>
*/
class SoapServerFactory
{
private $wsdlFile;
private $classmap;
private $converters;
private $options;
public function __construct($wsdlFile, Classmap $classmap, TypeConverterCollection $converters, array $options = array())
{
$this->wsdlFile = $wsdlFile;
$this->classmap = $classmap;
$this->converters = $converters;
$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)
{
return new \SoapServer(
$this->wsdlFile,
array(
'classmap' => $this->classmap->all(),
'typemap' => $this->converters->getTypemap(),
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
'cache_wsdl' => null !== $this->options['cache_type'] ? $this->options['cache_type'] : Cache::getType(),
)
);
}
}

View File

@ -14,10 +14,10 @@ use BeSimple\SoapBundle\Converter\TypeRepository;
use BeSimple\SoapBundle\ServiceBinding\MessageBinderInterface; use BeSimple\SoapBundle\ServiceBinding\MessageBinderInterface;
use BeSimple\SoapBundle\ServiceBinding\ServiceBinder; use BeSimple\SoapBundle\ServiceBinding\ServiceBinder;
use BeSimple\SoapBundle\ServiceDefinition\Dumper\DumperInterface; use BeSimple\SoapBundle\ServiceDefinition\Dumper\DumperInterface;
use BeSimple\SoapBundle\Soap\SoapServerFactory;
use BeSimple\SoapCommon\Classmap; use BeSimple\SoapCommon\Classmap;
use BeSimple\SoapCommon\Converter\TypeConverterCollection; use BeSimple\SoapCommon\Converter\TypeConverterCollection;
use BeSimple\SoapServer\SoapServerBuilder;
use Symfony\Component\Config\ConfigCache; use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\Config\Loader\LoaderInterface;
@ -38,7 +38,7 @@ class WebServiceContext
private $serviceDefinition; private $serviceDefinition;
private $serviceBinder; private $serviceBinder;
private $serverFactory; private $serverBuilder;
public function __construct(LoaderInterface $loader, DumperInterface $dumper, Classmap $classmap, TypeRepository $typeRepository, TypeConverterCollection $converters, array $options) { public function __construct(LoaderInterface $loader, DumperInterface $dumper, Classmap $classmap, TypeRepository $typeRepository, TypeConverterCollection $converters, array $options) {
$this->loader = $loader; $this->loader = $loader;
@ -100,20 +100,22 @@ class WebServiceContext
return $this->serviceBinder; return $this->serviceBinder;
} }
public function getServerFactory() public function getServerBuilder()
{ {
if (null === $this->serverFactory) { if (null === $this->serverBuilder) {
$this->serverFactory = new SoapServerFactory( $this->serverBuilder = SoapServerBuilder::createWithDefaults()
$this->getWsdlFile(), ->withWsdl($this->getWsdlFile())
$this->classmap, ->withClassmap($this->classmap)
$this->converters, ->withTypeConverters($this->converters)
array( ;
'debug' => $this->options['debug'],
'cache_type' => isset($this->options['cache_type']) ? $this->options['cache_type'] : null, if (!$this->options['debug']) {
) $this->serverBuilder->withWsdlCacheNone();
); } elseif (null !== $this->options['cache_type']) {
$this->serverBuilder->withWsdlCache($this->options['cache_type']);
}
} }
return $this->serverFactory; return $this->serverBuilder;
} }
} }