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-08-26 23:39:43 +02:00
|
|
|
use BeSimple\SoapBundle\Converter\TypeRepository;
|
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
|
|
|
|
2011-10-12 21:08:59 +02:00
|
|
|
use BeSimple\SoapCommon\Classmap;
|
|
|
|
|
2011-01-07 23:03:03 +01:00
|
|
|
/**
|
|
|
|
* @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-10-12 21:08:59 +02:00
|
|
|
private $classmap;
|
2011-08-26 23:39:43 +02:00
|
|
|
private $typeRepository;
|
2011-08-14 21:59:03 +02:00
|
|
|
private $options;
|
|
|
|
|
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-10-12 21:08:59 +02:00
|
|
|
public function __construct(AnnotationComplexTypeLoader $loader, Classmap $classmap, TypeRepository $typeRepository, array $options)
|
2011-07-23 20:06:42 +02:00
|
|
|
{
|
2011-08-26 23:39:43 +02:00
|
|
|
$this->loader = $loader;
|
2011-10-12 21:08:59 +02:00
|
|
|
$this->classmap = $classmap;
|
2011-08-26 23:39:43 +02:00
|
|
|
$this->typeRepository = $typeRepository;
|
|
|
|
$this->options = $options;
|
2011-07-23 20:06:42 +02:00
|
|
|
}
|
|
|
|
|
2011-08-14 21:59:03 +02:00
|
|
|
public function dumpServiceDefinition(ServiceDefinition $definition, $endpoint)
|
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 10:46:54 +02:00
|
|
|
$this->definition = $definition;
|
2011-10-12 21:08:59 +02:00
|
|
|
$this->wsdl = new Wsdl($this->typeRepository, $definition->getName(), $definition->getNamespace(), new WsdlTypeStrategy($this->loader, $this->classmap, $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');
|
2011-08-14 21:59:03 +02:00
|
|
|
$this->wsdl->addService($this->getServiceName(), $this->getPortName(), $this->qualify($this->getBindingName()), $endpoint);
|
2011-01-07 23:03:03 +01:00
|
|
|
|
2011-07-17 15:04:33 +02:00
|
|
|
foreach ($definition->getMethods() as $method) {
|
2011-08-14 18:00:28 +02:00
|
|
|
$requestHeaderParts =
|
|
|
|
$requestParts =
|
|
|
|
$responseParts = array();
|
|
|
|
|
|
|
|
foreach ($method->getHeaders() as $header) {
|
|
|
|
$requestHeaderParts[$header->getName()] = $this->wsdl->getType($header->getType()->getPhpType());
|
|
|
|
}
|
2011-01-07 23:03:03 +01:00
|
|
|
|
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-08-14 18:00:28 +02:00
|
|
|
if (!empty($requestHeaderParts)) {
|
|
|
|
$this->wsdl->addMessage($this->getRequestHeaderMessageName($method), $requestHeaderParts);
|
|
|
|
}
|
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-08-14 18:00:28 +02:00
|
|
|
$portOperation = $this->wsdl->addPortOperation(
|
|
|
|
$port,
|
|
|
|
$method->getName(),
|
|
|
|
$this->qualify($this->getRequestMessageName($method)),
|
|
|
|
$this->qualify($this->getResponseMessageName($method))
|
|
|
|
);
|
2011-11-17 19:58:23 +01:00
|
|
|
|
|
|
|
if (!empty($requestParts)) {
|
|
|
|
$portOperation->setAttribute('parameterOrder', implode(' ', array_keys($requestParts)));
|
|
|
|
}
|
2011-01-07 23:03:03 +01:00
|
|
|
|
2011-08-14 18:00:28 +02:00
|
|
|
$baseBinding = array(
|
2011-07-17 10:46:54 +02:00
|
|
|
'use' => 'literal',
|
|
|
|
'namespace' => $definition->getNamespace(),
|
2011-01-07 23:03:03 +01:00
|
|
|
'encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/',
|
|
|
|
);
|
2011-08-14 18:00:28 +02:00
|
|
|
|
|
|
|
$bindingOperation = $this->wsdl->addBindingOperation(
|
|
|
|
$binding,
|
|
|
|
$method->getName(),
|
|
|
|
array_merge(array('parts' => implode(' ', array_keys($requestParts))), $baseBinding),
|
|
|
|
array_merge(array('parts' => implode(' ', array_keys($responseParts))), $baseBinding)
|
|
|
|
);
|
|
|
|
$bindingOperation = $this->wsdl->addBindingOperationHeader(
|
|
|
|
$bindingOperation,
|
|
|
|
array_keys($requestHeaderParts),
|
|
|
|
array_merge(array('message' => $this->qualify($this->getRequestHeaderMessageName($method))), $baseBinding)
|
2011-01-07 23:03:03 +01:00
|
|
|
);
|
|
|
|
|
2011-07-17 15:04:33 +02:00
|
|
|
$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;
|
|
|
|
|
2011-08-14 21:59:03 +02:00
|
|
|
if ($this->options['stylesheet']) {
|
|
|
|
$stylesheet = $dom->createProcessingInstruction('xml-stylesheet', sprintf('type="text/xsl" href="%s"', $this->options['stylesheet']));
|
2011-07-17 15:04:33 +02:00
|
|
|
|
|
|
|
$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
|
|
|
}
|
|
|
|
|
2011-08-14 18:00:28 +02:00
|
|
|
protected function getRequestHeaderMessageName(Method $method)
|
|
|
|
{
|
|
|
|
return $method->getName().'Header';
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|