Merge remote-tracking branch 'origin/complextype_pretty_name'
This commit is contained in:
commit
bef19356d6
|
@ -15,7 +15,7 @@
|
||||||
<parameter key="besimple.soap.binder.response.documentwrapped.class">BeSimple\SoapBundle\ServiceBinding\DocumentLiteralWrappedResponseMessageBinder</parameter>
|
<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.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.type.repository.class">BeSimple\SoapBundle\Converter\TypeRepository</parameter>
|
||||||
<parameter key="besimple.soap.server.classmap.class">BeSimple\SoapCommon\Classmap</parameter>
|
<parameter key="besimple.soap.server.classmap.class">BeSimple\SoapServer\Classmap</parameter>
|
||||||
</parameters>
|
</parameters>
|
||||||
|
|
||||||
<services>
|
<services>
|
||||||
|
|
|
@ -51,8 +51,16 @@ You can expose only the properties (public, protected or private) of a complex t
|
||||||
|
|
||||||
use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;
|
use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Soap\Alias("User")
|
||||||
|
*/
|
||||||
class User
|
class User
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @Soap\ComplexType("int", nillable=true)
|
||||||
|
*/
|
||||||
|
private $id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Soap\ComplexType("string")
|
* @Soap\ComplexType("string")
|
||||||
*/
|
*/
|
||||||
|
@ -63,11 +71,6 @@ You can expose only the properties (public, protected or private) of a complex t
|
||||||
*/
|
*/
|
||||||
public $lastname;
|
public $lastname;
|
||||||
|
|
||||||
/**
|
|
||||||
* @Soap\ComplexType("int", nillable=true)
|
|
||||||
*/
|
|
||||||
private $id;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Soap\ComplexType("string")
|
* @Soap\ComplexType("string")
|
||||||
*/
|
*/
|
||||||
|
@ -135,3 +138,9 @@ ComplexType
|
||||||
`ComplexType` accepts the following options:
|
`ComplexType` accepts the following options:
|
||||||
|
|
||||||
* nillable: To specify that the value can be null
|
* nillable: To specify that the value can be null
|
||||||
|
|
||||||
|
Alias
|
||||||
|
-----
|
||||||
|
|
||||||
|
If you can Alias annotation, the name of your entity will be renamed in the WSDL generated.
|
||||||
|
With alias the name in WSDL will `User` instead of `Acme.DemoBundle.Entity.User` (name without Alias annotation).
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the BeSimpleSoapBundle.
|
||||||
|
*
|
||||||
|
* (c) Christian Kerl <christian-kerl@web.de>
|
||||||
|
* (c) Francis Besset <francis.besset@gmail.com>
|
||||||
|
*
|
||||||
|
* This source file is subject to the MIT license that is bundled
|
||||||
|
* with this source code in the file LICENSE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace BeSimple\SoapBundle\ServiceDefinition\Annotation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Annotation
|
||||||
|
*/
|
||||||
|
class Alias extends Configuration
|
||||||
|
{
|
||||||
|
private $value;
|
||||||
|
|
||||||
|
public function getValue()
|
||||||
|
{
|
||||||
|
return $this->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setValue($value)
|
||||||
|
{
|
||||||
|
$this->value = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAliasName()
|
||||||
|
{
|
||||||
|
return 'alias';
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,7 +21,7 @@ abstract class Configuration implements ConfigurationInterface
|
||||||
{
|
{
|
||||||
foreach ($values as $k => $v) {
|
foreach ($values as $k => $v) {
|
||||||
if (!method_exists($this, $name = 'set'.$k)) {
|
if (!method_exists($this, $name = 'set'.$k)) {
|
||||||
throw new \RuntimeException(sprintf('Unknown key "%s" for annotation "@%s".', $k, get_class($this)));
|
throw new \RuntimeException(sprintf('Unknown key "%s" for annotation "@%s".', $k, __CLASS__));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->$name($v);
|
$this->$name($v);
|
||||||
|
|
|
@ -22,6 +22,7 @@ use BeSimple\SoapBundle\Util\Collection;
|
||||||
*/
|
*/
|
||||||
class AnnotationComplexTypeLoader extends AnnotationClassLoader
|
class AnnotationComplexTypeLoader extends AnnotationClassLoader
|
||||||
{
|
{
|
||||||
|
private $aliasClass = 'BeSimple\SoapBundle\ServiceDefinition\Annotation\Alias';
|
||||||
private $complexTypeClass = 'BeSimple\SoapBundle\ServiceDefinition\Annotation\ComplexType';
|
private $complexTypeClass = 'BeSimple\SoapBundle\ServiceDefinition\Annotation\ComplexType';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,9 +41,14 @@ class AnnotationComplexTypeLoader extends AnnotationClassLoader
|
||||||
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
|
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
|
||||||
}
|
}
|
||||||
|
|
||||||
$class = new \ReflectionClass($class);
|
$annotations = array();
|
||||||
$collection = new Collection('getName', 'BeSimple\SoapBundle\ServiceDefinition\ComplexType');
|
|
||||||
|
|
||||||
|
$class = new \ReflectionClass($class);
|
||||||
|
if ($alias = $this->reader->getClassAnnotation($class, $this->aliasClass)) {
|
||||||
|
$annotations['alias'] = $alias->getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
$annotations['properties'] = new Collection('getName', 'BeSimple\SoapBundle\ServiceDefinition\ComplexType');
|
||||||
foreach ($class->getProperties() as $property) {
|
foreach ($class->getProperties() as $property) {
|
||||||
$complexType = $this->reader->getPropertyAnnotation($property, $this->complexTypeClass);
|
$complexType = $this->reader->getPropertyAnnotation($property, $this->complexTypeClass);
|
||||||
|
|
||||||
|
@ -51,10 +57,10 @@ class AnnotationComplexTypeLoader extends AnnotationClassLoader
|
||||||
$propertyComplexType->setValue($complexType->getValue());
|
$propertyComplexType->setValue($complexType->getValue());
|
||||||
$propertyComplexType->setNillable($complexType->isNillable());
|
$propertyComplexType->setNillable($complexType->isNillable());
|
||||||
$propertyComplexType->setName($property->getName());
|
$propertyComplexType->setName($property->getName());
|
||||||
$collection->add($propertyComplexType);
|
$annotations['properties']->add($propertyComplexType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $collection;
|
return $annotations;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -128,9 +128,20 @@ class ServiceDefinition
|
||||||
$this->classmap = $classmap;
|
$this->classmap = $classmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addDefinitionComplexType($type, Collection $complexType)
|
public function hasDefinitionComplexType($type)
|
||||||
{
|
{
|
||||||
$this->complexTypes[$type] = $complexType;
|
return isset($this->complexTypes[$type]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addDefinitionComplexType($type, array $definition)
|
||||||
|
{
|
||||||
|
if ($this->hasDefinitionComplexType($type)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->complexTypes[$type] = $definition;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDefinitionComplexTypes()
|
public function getDefinitionComplexTypes()
|
||||||
|
|
|
@ -36,44 +36,45 @@ class ComplexType extends AbstractComplexTypeStrategy
|
||||||
* @param string $type Name of the class to be specified
|
* @param string $type Name of the class to be specified
|
||||||
* @return string XSD Type for the given PHP type
|
* @return string XSD Type for the given PHP type
|
||||||
*/
|
*/
|
||||||
public function addComplexType($type)
|
public function addComplexType($classname)
|
||||||
{
|
{
|
||||||
$classmap = $this->definition->getClassmap();
|
$classmap = $this->definition->getClassmap();
|
||||||
|
if ($classmap->hasByClassname($classname)) {
|
||||||
if (null !== $soapType = $this->scanRegisteredTypes($type)) {
|
return 'tns:'.$classmap->getByClassname($classname);
|
||||||
return $soapType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->loader->supports($type)) {
|
if (!$this->loader->supports($classname)) {
|
||||||
throw new \InvalidArgumentException(sprintf('Cannot add a complex type "%s" that is not an object or where class could not be found in "ComplexType" strategy.', $type));
|
throw new \InvalidArgumentException(sprintf('Cannot add ComplexType "%s" because it is not an object or the class could not be found.', $classname));
|
||||||
}
|
}
|
||||||
|
|
||||||
$dom = $this->getContext()->toDomDocument();
|
$definitionComplexType = $this->loader->load($classname);
|
||||||
|
$classnameAlias = isset($definitionComplexType['alias']) ? $definitionComplexType['alias'] : $classname;
|
||||||
|
|
||||||
$soapTypeName = $this->getContext()->translateType($type);
|
$type = $this->getContext()->translateType($classnameAlias);
|
||||||
$soapType = 'tns:'.$soapTypeName;
|
$xmlType = 'tns:'.$type;
|
||||||
|
|
||||||
if (!$classmap->has($soapTypeName)) {
|
|
||||||
$classmap->add($soapTypeName, $type);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register type here to avoid recursion
|
// Register type here to avoid recursion
|
||||||
$this->getContext()->addType($type, $soapType);
|
$classmap->add($type, $classname);
|
||||||
|
$this->addXmlDefinition($definitionComplexType, $classname, $type);
|
||||||
|
|
||||||
|
return $xmlType;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function addXmlDefinition(array $definitionComplexType, $classname, $type)
|
||||||
|
{
|
||||||
|
$dom = $this->getContext()->toDomDocument();
|
||||||
$complexType = $dom->createElement('xsd:complexType');
|
$complexType = $dom->createElement('xsd:complexType');
|
||||||
$complexType->setAttribute('name', $soapTypeName);
|
$complexType->setAttribute('name', $type);
|
||||||
|
|
||||||
$all = $dom->createElement('xsd:all');
|
$all = $dom->createElement('xsd:all');
|
||||||
|
|
||||||
$definitionComplexType = $this->loader->load($type);
|
$elements = array();
|
||||||
$this->definition->addDefinitionComplexType($type, $definitionComplexType);
|
foreach ($definitionComplexType['properties'] as $property) {
|
||||||
|
|
||||||
foreach ($definitionComplexType as $annotationComplexType) {
|
|
||||||
$element = $dom->createElement('xsd:element');
|
$element = $dom->createElement('xsd:element');
|
||||||
$element->setAttribute('name', $propertyName = $annotationComplexType->getName());
|
$element->setAttribute('name', $property->getName());
|
||||||
$element->setAttribute('type', $this->getContext()->getType(trim($annotationComplexType->getValue())));
|
$element->setAttribute('type', $this->getContext()->getType($property->getValue()));
|
||||||
|
|
||||||
if ($annotationComplexType->isNillable()) {
|
if ($property->isNillable()) {
|
||||||
$element->setAttribute('nillable', 'true');
|
$element->setAttribute('nillable', 'true');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,6 +84,6 @@ class ComplexType extends AbstractComplexTypeStrategy
|
||||||
$complexType->appendChild($all);
|
$complexType->appendChild($all);
|
||||||
$this->getContext()->getSchema()->appendChild($complexType);
|
$this->getContext()->getSchema()->appendChild($complexType);
|
||||||
|
|
||||||
return $soapType;
|
$this->definition->addDefinitionComplexType($type, $definitionComplexType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the BeSimpleSoapBundle.
|
||||||
|
*
|
||||||
|
* (c) Christian Kerl <christian-kerl@web.de>
|
||||||
|
* (c) Francis Besset <francis.besset@gmail.com>
|
||||||
|
*
|
||||||
|
* This source file is subject to the MIT license that is bundled
|
||||||
|
* with this source code in the file LICENSE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace BeSimple\SoapServer;
|
||||||
|
|
||||||
|
use BeSimple\SoapCommon\Classmap as BaseClassmap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Francis Besset <francis.besset@gmail.com>
|
||||||
|
*/
|
||||||
|
class Classmap extends BaseClassmap
|
||||||
|
{
|
||||||
|
protected $classmapInversed = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function add($type, $classname)
|
||||||
|
{
|
||||||
|
parent::add($type, $classname);
|
||||||
|
|
||||||
|
$this->classmapInversed[$classname] = $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getByClassname($classname)
|
||||||
|
{
|
||||||
|
if (!$this->hasByClassname($classname)) {
|
||||||
|
throw new \InvalidArgumentException(sprintf('The classname "%s" was not found in %s', $classname, __CLASS__));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->classmapInversed[$classname];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasByClassname($classname)
|
||||||
|
{
|
||||||
|
return isset($this->classmapInversed[$classname]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue