Used BeSimple\SoapCommon\Classmap for the webservice context

This commit is contained in:
Francis Besset 2011-10-12 21:08:59 +02:00
parent 4a7ec164e5
commit 70a85460c9
7 changed files with 38 additions and 25 deletions

View File

@ -51,7 +51,7 @@ class BeSimpleSoapExtension extends Extension
$this->registerCacheConfiguration($config['cache'], $container, $loader);
if (isset($config['clients'])) {
if (!empty($config['clients'])) {
$this->registerClientConfiguration($config['clients'], $container, $loader);
}
@ -146,9 +146,9 @@ class BeSimpleSoapExtension extends Extension
$options = $container
->getDefinition('besimple.soap.context.'.$bindingSuffix)
->getArgument(4);
->getArgument(5);
$definition->replaceArgument(4, array_merge($options, $config));
$definition->replaceArgument(5, array_merge($options, $config));
}
private function getCacheType($type)

View File

@ -15,6 +15,7 @@
<parameter key="besimple.soap.binder.response.documentwrapped.class">BeSimple\SoapBundle\ServiceBinding\DocumentLiteralWrappedResponseMessageBinder</parameter>
<parameter key="besimple.soap.definition.dumper.wsdl.rpcliteral.class">BeSimple\SoapBundle\ServiceDefinition\Dumper\WsdlDumper</parameter>
<parameter key="besimple.soap.type.repository.class">BeSimple\SoapBundle\Converter\TypeRepository</parameter>
<parameter key="besimple.soap.server.classmap.class">BeSimple\SoapCommon\Classmap</parameter>
</parameters>
<services>
@ -23,6 +24,7 @@
<service id="besimple.soap.context.rpcliteral" class="%besimple.soap.context.class%" abstract="true">
<argument type="service" id="besimple.soap.definition.loader" />
<argument type="service" id="besimple.soap.definition.dumper.wsdl.rpcliteral" />
<argument type="service" id="besimple.soap.server.classmap" />
<argument type="service" id="besimple.soap.type.repository" />
<argument type="service" id="besimple.soap.converter.collection" />
<argument type="collection">
@ -39,6 +41,7 @@
<service id="besimple.soap.context.documentwrapped" class="%besimple.soap.context.class%" abstract="true">
<argument type="service" id="besimple.soap.definition.loader" />
<argument type="service" id="besimple.soap.definition.dumper.wsdl.documentwrapped" />
<argument type="service" id="besimple.soap.server.classmap" />
<argument type="service" id="besimple.soap.type.repository" />
<argument type="service" id="besimple.soap.converter.collection" />
<argument type="collection">
@ -54,12 +57,15 @@
<service id="besimple.soap.definition.dumper.wsdl.rpcliteral" class="%besimple.soap.definition.dumper.wsdl.rpcliteral.class%">
<argument type="service" id="besimple.soap.definition.loader.annot_complextype" />
<argument type="service" id="besimple.soap.server.classmap" />
<argument type="service" id="besimple.soap.type.repository" />
<argument type="collection">
<argument key="stylesheet">%besimple.soap.definition.dumper.options.stylesheet%</argument>
</argument>
</service>
<service id="besimple.soap.server.classmap" class="%besimple.soap.server.classmap.class%" public="false" />
<service id="besimple.soap.type.repository" class="%besimple.soap.type.repository.class%">
<call method="addXmlNamespace">
<argument>xsd</argument>

View File

@ -18,21 +18,25 @@ use BeSimple\SoapBundle\ServiceDefinition\Loader\AnnotationComplexTypeLoader;
use BeSimple\SoapBundle\Util\Assert;
use BeSimple\SoapBundle\Util\QName;
use BeSimple\SoapCommon\Classmap;
/**
* @author Christian Kerl <christian-kerl@web.de>
*/
class WsdlDumper implements DumperInterface
{
private $loader;
private $classmap;
private $typeRepository;
private $options;
private $wsdl;
private $definition;
public function __construct(AnnotationComplexTypeLoader $loader, TypeRepository $typeRepository, array $options)
public function __construct(AnnotationComplexTypeLoader $loader, Classmap $classmap, TypeRepository $typeRepository, array $options)
{
$this->loader = $loader;
$this->classmap = $classmap;
$this->typeRepository = $typeRepository;
$this->options = $options;
}
@ -42,7 +46,7 @@ class WsdlDumper implements DumperInterface
Assert::thatArgumentNotNull('definition', $definition);
$this->definition = $definition;
$this->wsdl = new Wsdl($this->typeRepository, $definition->getName(), $definition->getNamespace(), new WsdlTypeStrategy($this->loader, $definition));
$this->wsdl = new Wsdl($this->typeRepository, $definition->getName(), $definition->getNamespace(), new WsdlTypeStrategy($this->loader, $this->classmap, $definition));
$port = $this->wsdl->addPortType($this->getPortTypeName());
$binding = $this->wsdl->addBinding($this->getBindingName(), $this->qualify($this->getPortTypeName()));

View File

@ -15,6 +15,8 @@ use BeSimple\SoapBundle\ServiceDefinition\Loader\AnnotationComplexTypeLoader;
use BeSimple\SoapBundle\ServiceDefinition\Strategy\ComplexType;
use BeSimple\SoapBundle\Util\String;
use BeSimple\SoapCommon\Classmap;
use Zend\Soap\Exception;
use Zend\Soap\Wsdl as BaseWsdl;
use Zend\Soap\Wsdl\Strategy;
@ -30,14 +32,16 @@ class WsdlTypeStrategy implements Strategy
private $context;
private $loader;
private $classmap;
private $definition;
private $typeStrategy;
private $arrayStrategy;
public function __construct(AnnotationComplexTypeLoader $loader, ServiceDefinition $definition)
public function __construct(AnnotationComplexTypeLoader $loader, Classmap $classmap, ServiceDefinition $definition)
{
$this->loader = $loader;
$this->classmap = $classmap;
$this->definition = $definition;
}
@ -86,7 +90,7 @@ class WsdlTypeStrategy implements Strategy
private function getTypeStrategy()
{
if (!$this->typeStrategy) {
$this->typeStrategy = new ComplexType($this->loader, $this->definition);
$this->typeStrategy = new ComplexType($this->loader, $this->classmap, $this->definition);
$this->typeStrategy->setContext($this->context);
}

View File

@ -12,6 +12,7 @@ namespace BeSimple\SoapBundle\ServiceDefinition\Strategy;
use BeSimple\SoapBundle\ServiceDefinition\Loader\AnnotationComplexTypeLoader;
use BeSimple\SoapCommon\Classmap;
use Zend\Soap\Wsdl;
use Zend\Soap\Wsdl\Strategy\AbstractStrategy;
@ -21,11 +22,13 @@ use Zend\Soap\Wsdl\Strategy\AbstractStrategy;
class ComplexType extends AbstractStrategy
{
private $loader;
private $classmap;
private $definition;
public function __construct(AnnotationComplexTypeLoader $loader, $definition)
public function __construct(AnnotationComplexTypeLoader $loader, Classmap $classmap, $definition)
{
$this->loader = $loader;
$this->classmap = $classmap;
$this->definition = $definition;
}
@ -50,6 +53,8 @@ class ComplexType extends AbstractStrategy
$soapTypeName = Wsdl::translateType($type);
$soapType = 'tns:'.$soapTypeName;
$this->classmap->add($soapTypeName, $type);
// Register type here to avoid recursion
$this->getContext()->addType($type, $soapType);

View File

@ -11,6 +11,7 @@
namespace BeSimple\SoapBundle\Soap;
use BeSimple\SoapCommon\Cache;
use BeSimple\SoapCommon\Classmap;
use BeSimple\SoapCommon\Converter\TypeConverterCollection;
use Zend\Soap\Wsdl;
@ -25,11 +26,12 @@ class SoapServerFactory
private $converters;
private $options;
public function __construct($wsdlFile, array $classmap, TypeConverterCollection $converters, array $options = array())
public function __construct($wsdlFile, Classmap $classmap, TypeConverterCollection $converters, array $options = array())
{
$this->wsdlFile = $wsdlFile;
$this->classmap = $this->fixSoapServerClassmap($classmap);
$this->classmap = $classmap;
$this->converters = $converters;
$this->setOptions($options);
}
@ -66,22 +68,11 @@ class SoapServerFactory
return new \SoapServer(
$this->wsdlFile,
array(
'classmap' => $this->classmap,
'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(),
)
);
}
private function fixSoapServerClassmap($classmap)
{
$classmapFixed = array();
foreach ($classmap as $class => $definition) {
$classmapFixed[Wsdl::translateType($class)] = $class;
}
return $classmapFixed;
}
}

View File

@ -16,6 +16,7 @@ use BeSimple\SoapBundle\ServiceBinding\ServiceBinder;
use BeSimple\SoapBundle\ServiceDefinition\Dumper\DumperInterface;
use BeSimple\SoapBundle\Soap\SoapServerFactory;
use BeSimple\SoapCommon\Classmap;
use BeSimple\SoapCommon\Converter\TypeConverterCollection;
use Symfony\Component\Config\ConfigCache;
@ -39,10 +40,12 @@ class WebServiceContext
private $serviceBinder;
private $serverFactory;
public function __construct(LoaderInterface $loader, DumperInterface $dumper, 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->wsdlFileDumper = $dumper;
$this->classmap = $classmap;
$this->typeRepository = $typeRepository;
$this->converters = $converters;
@ -102,7 +105,7 @@ class WebServiceContext
if (null === $this->serverFactory) {
$this->serverFactory = new SoapServerFactory(
$this->getWsdlFile(),
$this->serviceDefinition->getDefinitionComplexTypes(),
$this->classmap,
$this->converters,
array(
'debug' => $this->options['debug'],