2011-01-07 23:03:03 +01:00
|
|
|
<?php
|
|
|
|
/*
|
2011-07-18 22:43:12 +02:00
|
|
|
* This file is part of the BeSimpleSoapBundle.
|
2011-01-07 23:03:03 +01:00
|
|
|
*
|
|
|
|
* (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.
|
|
|
|
*/
|
|
|
|
|
2011-07-18 22:43:12 +02:00
|
|
|
namespace BeSimple\SoapBundle\ServiceDefinition\Dumper;
|
2011-01-07 23:03:03 +01:00
|
|
|
|
2011-07-18 22:43:12 +02:00
|
|
|
use BeSimple\SoapBundle\ServiceDefinition\Method;
|
|
|
|
use BeSimple\SoapBundle\ServiceDefinition\Type;
|
|
|
|
use BeSimple\SoapBundle\ServiceDefinition\ServiceDefinition;
|
2011-07-23 20:06:42 +02:00
|
|
|
use BeSimple\SoapBundle\ServiceDefinition\Loader\AnnotationComplexTypeLoader;
|
2011-07-18 22:43:12 +02:00
|
|
|
use BeSimple\SoapBundle\Util\Assert;
|
|
|
|
use BeSimple\SoapBundle\Util\QName;
|
2011-01-07 23:03:03 +01:00
|
|
|
|
|
|
|
use Zend\Soap\Wsdl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Christian Kerl <christian-kerl@web.de>
|
|
|
|
*/
|
2011-04-07 21:49:59 +02:00
|
|
|
class WsdlDumper implements DumperInterface
|
2011-01-07 23:03:03 +01:00
|
|
|
{
|
2011-07-23 20:06:42 +02:00
|
|
|
private $loader;
|
2011-07-17 15:04:33 +02:00
|
|
|
private $wsdl;
|
2011-02-03 01:04:12 +01:00
|
|
|
private $definition;
|
2011-07-14 17:45:03 +02:00
|
|
|
|
2011-07-23 20:06:42 +02:00
|
|
|
public function __construct(AnnotationComplexTypeLoader $loader)
|
|
|
|
{
|
|
|
|
$this->loader = $loader;
|
|
|
|
}
|
|
|
|
|
2011-04-07 21:49:59 +02:00
|
|
|
public function dumpServiceDefinition(ServiceDefinition $definition, array $options = array())
|
2011-01-07 23:03:03 +01:00
|
|
|
{
|
2011-07-17 10:46:54 +02:00
|
|
|
Assert::thatArgumentNotNull('definition', $definition);
|
2011-01-07 23:03:03 +01:00
|
|
|
|
2011-07-17 15:04:33 +02:00
|
|
|
$options = array_merge(array('endpoint' => '', 'stylesheet' => null), $options);
|
|
|
|
|
2011-07-17 10:46:54 +02:00
|
|
|
$this->definition = $definition;
|
2011-07-23 20:06:42 +02:00
|
|
|
$this->wsdl = new Wsdl($definition->getName(), $definition->getNamespace(), new WsdlTypeStrategy($this->loader, $definition));
|
2011-07-17 15:04:33 +02:00
|
|
|
$port = $this->wsdl->addPortType($this->getPortTypeName());
|
|
|
|
$binding = $this->wsdl->addBinding($this->getBindingName(), $this->qualify($this->getPortTypeName()));
|
2011-07-14 17:45:03 +02:00
|
|
|
|
2011-07-17 15:04:33 +02:00
|
|
|
$this->wsdl->addSoapBinding($binding, 'rpc');
|
|
|
|
$this->wsdl->addService($this->getServiceName(), $this->getPortName(), $this->qualify($this->getBindingName()), $options['endpoint']);
|
2011-01-07 23:03:03 +01:00
|
|
|
|
2011-07-17 15:04:33 +02:00
|
|
|
foreach ($definition->getMethods() as $method) {
|
2011-07-17 10:46:54 +02:00
|
|
|
$requestParts = array();
|
2011-01-07 23:03:03 +01:00
|
|
|
$responseParts = array();
|
|
|
|
|
2011-07-17 15:04:33 +02:00
|
|
|
foreach ($method->getArguments() as $argument) {
|
|
|
|
$requestParts[$argument->getName()] = $this->wsdl->getType($argument->getType()->getPhpType());
|
2011-01-07 23:03:03 +01:00
|
|
|
}
|
|
|
|
|
2011-07-17 15:04:33 +02:00
|
|
|
if ($method->getReturn() !== null) {
|
|
|
|
$responseParts['return'] = $this->wsdl->getType($method->getReturn()->getPhpType());
|
2011-04-09 00:38:39 +02:00
|
|
|
}
|
2011-01-07 23:03:03 +01:00
|
|
|
|
2011-07-17 15:04:33 +02:00
|
|
|
$this->wsdl->addMessage($this->getRequestMessageName($method), $requestParts);
|
|
|
|
$this->wsdl->addMessage($this->getResponseMessageName($method), $responseParts);
|
2011-01-07 23:03:03 +01:00
|
|
|
|
2011-07-17 15:04:33 +02:00
|
|
|
$portOperation = $this->wsdl->addPortOperation($port, $method->getName(), $this->qualify($this->getRequestMessageName($method)), $this->qualify($this->getResponseMessageName($method)));
|
2011-01-07 23:03:03 +01:00
|
|
|
$portOperation->setAttribute('parameterOrder', implode(' ', array_keys($requestParts)));
|
|
|
|
|
|
|
|
$bindingInput = array(
|
2011-07-17 10:46:54 +02:00
|
|
|
'parts' => implode(' ', array_keys($requestParts)),
|
|
|
|
'use' => 'literal',
|
|
|
|
'namespace' => $definition->getNamespace(),
|
2011-01-07 23:03:03 +01:00
|
|
|
'encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/',
|
|
|
|
);
|
|
|
|
$bindingOutput = array(
|
2011-07-17 10:46:54 +02:00
|
|
|
'parts' => implode(' ', array_keys($responseParts)),
|
|
|
|
'use' => 'literal',
|
|
|
|
'namespace' => $definition->getNamespace(),
|
2011-01-07 23:03:03 +01:00
|
|
|
'encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/',
|
|
|
|
);
|
|
|
|
|
2011-07-17 15:04:33 +02:00
|
|
|
$bindingOperation = $this->wsdl->addBindingOperation($binding, $method->getName(), $bindingInput, $bindingOutput);
|
|
|
|
$this->wsdl->addSoapOperation($bindingOperation, $this->getSoapOperationName($method));
|
2011-01-07 23:03:03 +01:00
|
|
|
}
|
|
|
|
|
2011-02-03 01:04:12 +01:00
|
|
|
$this->definition = null;
|
|
|
|
|
2011-07-17 15:04:33 +02:00
|
|
|
$dom = $this->wsdl->toDomDocument();
|
|
|
|
$dom->formatOutput = true;
|
|
|
|
|
|
|
|
if (null !== $options['stylesheet']) {
|
|
|
|
$stylesheet = $dom->createProcessingInstruction('xml-stylesheet', sprintf('type="text/xsl" href="%s"', $options['stylesheet']));
|
|
|
|
|
|
|
|
$dom->insertBefore($stylesheet, $dom->documentElement);
|
|
|
|
}
|
2011-07-14 17:45:03 +02:00
|
|
|
|
2011-07-17 19:41:06 +02:00
|
|
|
return $this->wsdl->toXml();
|
2011-01-07 23:03:03 +01:00
|
|
|
}
|
2011-04-09 00:38:39 +02:00
|
|
|
|
2011-07-17 15:04:33 +02:00
|
|
|
protected function qualify($name, $namespace = null)
|
|
|
|
{
|
|
|
|
if($namespace === null) {
|
|
|
|
$namespace = $this->definition->getNamespace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->wsdl->toDomDocument()->lookupPrefix($namespace).':'.$name;
|
|
|
|
}
|
|
|
|
|
2011-04-09 00:38:39 +02:00
|
|
|
protected function getPortName()
|
|
|
|
{
|
2011-07-17 10:46:54 +02:00
|
|
|
return $this->definition->getName().'Port';
|
2011-04-09 00:38:39 +02:00
|
|
|
}
|
2011-07-14 17:45:03 +02:00
|
|
|
|
2011-02-03 01:04:12 +01:00
|
|
|
protected function getPortTypeName()
|
2011-01-07 23:03:03 +01:00
|
|
|
{
|
2011-07-17 10:46:54 +02:00
|
|
|
return $this->definition->getName().'PortType';
|
2011-01-07 23:03:03 +01:00
|
|
|
}
|
|
|
|
|
2011-02-03 01:04:12 +01:00
|
|
|
protected function getBindingName()
|
2011-01-07 23:03:03 +01:00
|
|
|
{
|
2011-07-17 10:46:54 +02:00
|
|
|
return $this->definition->getName().'Binding';
|
2011-01-07 23:03:03 +01:00
|
|
|
}
|
|
|
|
|
2011-02-03 01:04:12 +01:00
|
|
|
protected function getServiceName()
|
2011-01-07 23:03:03 +01:00
|
|
|
{
|
2011-07-17 10:46:54 +02:00
|
|
|
return $this->definition->getName().'Service';
|
2011-01-07 23:03:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getRequestMessageName(Method $method)
|
|
|
|
{
|
2011-07-17 10:46:54 +02:00
|
|
|
return $method->getName().'Request';
|
2011-01-07 23:03:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getResponseMessageName(Method $method)
|
|
|
|
{
|
2011-07-17 10:46:54 +02:00
|
|
|
return $method->getName().'Response';
|
2011-01-07 23:03:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getSoapOperationName(Method $method)
|
|
|
|
{
|
2011-07-17 10:46:54 +02:00
|
|
|
return $this->definition->getNamespace().$method->getName();
|
2011-01-07 23:03:03 +01:00
|
|
|
}
|
2011-07-17 15:04:33 +02:00
|
|
|
}
|