added namespace to service definition;

This commit is contained in:
Christian Kerl 2011-02-03 01:04:12 +01:00
parent 79da80bdb9
commit e53b83616b
3 changed files with 48 additions and 28 deletions

View File

@ -10,6 +10,8 @@
namespace Bundle\WebServiceBundle\DependencyInjection;
use Bundle\WebServiceBundle\Util\Assert;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
@ -48,12 +50,11 @@ class WebServiceExtension extends Extension
protected function registerServiceDefinitionConfig(array $config, ContainerBuilder $configuration)
{
if(!isset($config['name']))
{
throw new \InvalidArgumentException();
}
Assert::thatArgument('config.name', isset($config['name']));
Assert::thatArgument('config.namespace', isset($config['namespace']));
$configuration->setParameter('webservice.definition.name', $config['name']);
$configuration->setParameter('webservice.definition.namespace', $config['namespace']);
$configuration->setParameter('webservice.definition.resource', isset($config['resource']) ? $config['resource'] : null);
$configuration->setParameter('webservice.definition.wsdl', isset($config['wsdl']) ? $config['wsdl'] : null);
}

View File

@ -24,28 +24,21 @@ use Zend\Soap\Wsdl;
*/
class WsdlFileDumper extends FileDumper
{
private $namespace;
public function __construct($file, $namespace)
{
parent::__construct($file);
Assert::thatArgumentNotNull('namespace', $namespace);
$this->namespace = $namespace;
}
private $definition;
public function dumpServiceDefinition(ServiceDefinition $definition)
{
Assert::thatArgumentNotNull('definition', $definition);
$wsdl = new Wsdl($definition->getName(), $this->namespace);
$this->definition = $definition;
$port = $wsdl->addPortType($this->getPortTypeName($definition));
$binding = $wsdl->addBinding($this->getBindingName($definition), $this->getPortTypeName($definition));
$wsdl = new Wsdl($definition->getName(), $definition->getNamespace());
$port = $wsdl->addPortType($this->getPortTypeName());
$binding = $wsdl->addBinding($this->getBindingName(), $this->getPortTypeName());
$wsdl->addSoapBinding($binding, 'document');
$wsdl->addService($this->getServiceName($definition), $this->getPortTypeName($definition), $this->getBindingName($definition), 'http://localhost/service/');
$wsdl->addService($this->getServiceName(), $this->getPortTypeName(), $this->getBindingName(), '');
foreach($definition->getMethods() as $method)
{
@ -68,13 +61,13 @@ class WsdlFileDumper extends FileDumper
$bindingInput = array(
'parts' => implode(' ', array_keys($requestParts)),
'use' => 'literal',
'namespace' => $this->namespace,
'namespace' => $definition->getNamespace(),
'encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/',
);
$bindingOutput = array(
'parts' => implode(' ', array_keys($responseParts)),
'use' => 'literal',
'namespace' => $this->namespace,
'namespace' => $definition->getNamespace(),
'encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/',
);
@ -83,21 +76,25 @@ class WsdlFileDumper extends FileDumper
}
$wsdl->dump($this->file);
$this->definition = null;
return $this->file;
}
protected function getPortTypeName(ServiceDefinition $definition)
protected function getPortTypeName()
{
return $definition->getName() . 'PortType';
return $this->definition->getName() . 'PortType';
}
protected function getBindingName(ServiceDefinition $definition)
protected function getBindingName()
{
return $definition->getName() . 'Binding';
return $this->definition->getName() . 'Binding';
}
protected function getServiceName(ServiceDefinition $definition)
protected function getServiceName()
{
return $definition->getName() . 'Service';
return $this->definition->getName() . 'Service';
}
protected function getRequestMessageName(Method $method)
@ -112,6 +109,6 @@ class WsdlFileDumper extends FileDumper
protected function getSoapOperationName(Method $method)
{
return $this->namespace . $method->getName();
return $this->definition->getNamespace() . $method->getName();
}
}

View File

@ -19,6 +19,11 @@ class ServiceDefinition
*/
private $name;
/**
* @var string
*/
private $namespace;
/**
* @var \Bundle\WebServiceBundle\Util\Collection
*/
@ -29,9 +34,10 @@ class ServiceDefinition
*/
private $headers;
public function __construct($name = null, array $methods = array(), array $headers = array())
public function __construct($name = null, $namespace = null, array $methods = array(), array $headers = array())
{
$this->setName($name);
$this->setNamespace($namespace);
$this->setMethods($methods);
$this->setHeaders($headers);
}
@ -52,6 +58,22 @@ class ServiceDefinition
$this->name = $name;
}
/**
* @return string
*/
public function getNamespace()
{
return $this->namespace;
}
/**
* @param string $namespace
*/
public function setNamespace($namespace)
{
$this->namespace = $namespace;
}
/**
* @return \Bundle\WebServiceBundle\Util\Collection
*/