BeSimpleSoap/ServiceDefinition/Dumper/WsdlDumper.php

116 lines
4.0 KiB
PHP
Raw Normal View History

<?php
/*
* This file is part of the WebServiceBundle.
*
* (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 Bundle\WebServiceBundle\ServiceDefinition\Dumper;
use Bundle\WebServiceBundle\ServiceDefinition\Method;
use Bundle\WebServiceBundle\ServiceDefinition\ServiceDefinition;
use Bundle\WebServiceBundle\Util\Assert;
use Zend\Soap\Wsdl;
/**
* @author Christian Kerl <christian-kerl@web.de>
*/
class WsdlDumper implements DumperInterface
{
2011-02-03 01:04:12 +01:00
private $definition;
2011-07-14 17:45:03 +02:00
public function dumpServiceDefinition(ServiceDefinition $definition, array $options = array())
{
$options = array_merge(array('endpoint' => ''), $options);
2011-07-14 17:45:03 +02:00
Assert::thatArgumentNotNull('definition', $definition);
$this->definition = $definition;
$wsdl = new Wsdl($definition->getName(), $definition->getNamespace());
$port = $wsdl->addPortType($this->getPortTypeName());
$binding = $wsdl->addBinding($this->getBindingName(), 'tns:' . $this->getPortTypeName());
2011-07-14 17:45:03 +02:00
$wsdl->addSoapBinding($binding, 'rpc');
$wsdl->addService($this->getServiceName(), $this->getPortName(), 'tns:' . $this->getBindingName(), $options['endpoint']);
2011-07-14 17:45:03 +02:00
foreach($definition->getMethods() as $method) {
$requestParts = array();
$responseParts = array();
2011-07-14 17:45:03 +02:00
foreach($method->getArguments() as $argument) {
$requestParts[$argument->getName()] = $wsdl->getType($argument->getType()->getPhpType());
}
2011-07-14 17:45:03 +02:00
if($method->getReturn() !== null) {
$responseParts['return'] = $wsdl->getType($method->getReturn()->getPhpType());
}
$wsdl->addMessage($this->getRequestMessageName($method), $requestParts);
$wsdl->addMessage($this->getResponseMessageName($method), $responseParts);
$portOperation = $wsdl->addPortOperation($port, $method->getName(), 'tns:' . $this->getRequestMessageName($method), 'tns:' . $this->getResponseMessageName($method));
$portOperation->setAttribute('parameterOrder', implode(' ', array_keys($requestParts)));
$bindingInput = array(
'parts' => implode(' ', array_keys($requestParts)),
'use' => 'literal',
'namespace' => $definition->getNamespace(),
'encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/',
);
$bindingOutput = array(
'parts' => implode(' ', array_keys($responseParts)),
'use' => 'literal',
'namespace' => $definition->getNamespace(),
'encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/',
);
$bindingOperation = $wsdl->addBindingOperation($binding, $method->getName(), $bindingInput, $bindingOutput);
$wsdl->addSoapOperation($bindingOperation, $this->getSoapOperationName($method));
}
2011-02-03 01:04:12 +01:00
$this->definition = null;
$wsdl->toDomDocument()->formatOutput = true;
2011-07-14 17:45:03 +02:00
return $wsdl->toXml();
}
protected function getPortName()
{
return $this->definition->getName().'Port';
}
2011-07-14 17:45:03 +02:00
2011-02-03 01:04:12 +01:00
protected function getPortTypeName()
{
return $this->definition->getName().'PortType';
}
2011-02-03 01:04:12 +01:00
protected function getBindingName()
{
return $this->definition->getName().'Binding';
}
2011-02-03 01:04:12 +01:00
protected function getServiceName()
{
return $this->definition->getName().'Service';
}
protected function getRequestMessageName(Method $method)
{
return $method->getName().'Request';
}
protected function getResponseMessageName(Method $method)
{
return $method->getName().'Response';
}
protected function getSoapOperationName(Method $method)
{
return $this->definition->getNamespace().$method->getName();
}
2011-07-14 17:45:03 +02:00
}