Add minOccurs annotation support on complexType
This commit is contained in:
parent
30850d7a01
commit
e024833d48
|
@ -18,6 +18,7 @@ class ComplexType extends Configuration
|
||||||
private $name;
|
private $name;
|
||||||
private $value;
|
private $value;
|
||||||
private $isNillable = false;
|
private $isNillable = false;
|
||||||
|
private $minOccurs = 1;
|
||||||
|
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
|
@ -34,6 +35,11 @@ class ComplexType extends Configuration
|
||||||
return $this->isNillable;
|
return $this->isNillable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getIsNillable()
|
||||||
|
{
|
||||||
|
return $this->isNillable;
|
||||||
|
}
|
||||||
|
|
||||||
public function setName($name)
|
public function setName($name)
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
|
@ -49,6 +55,21 @@ class ComplexType extends Configuration
|
||||||
$this->isNillable = (bool) $isNillable;
|
$this->isNillable = (bool) $isNillable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setIsNillable($isNillable)
|
||||||
|
{
|
||||||
|
$this->isNillable = (bool) $isNillable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMinOccurs($minOccurs)
|
||||||
|
{
|
||||||
|
$this->minOccurs = $minOccurs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMinOccurs()
|
||||||
|
{
|
||||||
|
return $this->minOccurs;
|
||||||
|
}
|
||||||
|
|
||||||
public function getAliasName()
|
public function getAliasName()
|
||||||
{
|
{
|
||||||
return 'complextype';
|
return 'complextype';
|
||||||
|
|
|
@ -20,6 +20,7 @@ class ComplexType
|
||||||
private $name;
|
private $name;
|
||||||
private $value;
|
private $value;
|
||||||
private $isNillable = false;
|
private $isNillable = false;
|
||||||
|
private $minOccurs = 1;
|
||||||
|
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
|
@ -50,4 +51,14 @@ class ComplexType
|
||||||
{
|
{
|
||||||
$this->isNillable = (bool) $isNillable;
|
$this->isNillable = (bool) $isNillable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setMinOccurs($minOccurs)
|
||||||
|
{
|
||||||
|
$this->minOccurs = $minOccurs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMinOccurs()
|
||||||
|
{
|
||||||
|
return $this->minOccurs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ class AnnotationComplexTypeLoader extends AnnotationClassLoader
|
||||||
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
|
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
|
||||||
}
|
}
|
||||||
|
|
||||||
$annotations = array();
|
$annotations = [];
|
||||||
|
|
||||||
$class = new \ReflectionClass($class);
|
$class = new \ReflectionClass($class);
|
||||||
if ($alias = $this->reader->getClassAnnotation($class, $this->aliasClass)) {
|
if ($alias = $this->reader->getClassAnnotation($class, $this->aliasClass)) {
|
||||||
|
@ -59,6 +59,7 @@ 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());
|
||||||
|
$propertyComplexType->setMinOccurs($complexType->getMinOccurs());
|
||||||
$annotations['properties']->add($propertyComplexType);
|
$annotations['properties']->add($propertyComplexType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,7 +73,7 @@ class AnnotationComplexTypeLoader extends AnnotationClassLoader
|
||||||
* @param mixed $resource A resource
|
* @param mixed $resource A resource
|
||||||
* @param string $type The resource type
|
* @param string $type The resource type
|
||||||
*
|
*
|
||||||
* @return Boolean True if this class supports the given resource, false otherwise
|
* @return bool True if this class supports the given resource, false otherwise
|
||||||
*/
|
*/
|
||||||
public function supports($resource, $type = null)
|
public function supports($resource, $type = null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,7 +25,7 @@ class Message
|
||||||
public function __construct($name)
|
public function __construct($name)
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->parts = array();
|
$this->parts = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName()
|
public function getName()
|
||||||
|
@ -48,13 +48,13 @@ class Message
|
||||||
return 0 === count($this->parts) ? true : false;
|
return 0 === count($this->parts) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add($name, $phpType, $nillable = false)
|
public function add($name, $phpType, $nillable = false, $minOccurs = 1)
|
||||||
{
|
{
|
||||||
if ($phpType instanceof TypeInterface) {
|
if ($phpType instanceof TypeInterface) {
|
||||||
$phpType = $phpType->getPhpType();
|
$phpType = $phpType->getPhpType();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->parts[$name] = new Part($name, $phpType, $nillable);
|
$this->parts[$name] = new Part($name, $phpType, $nillable, $minOccurs);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,11 +20,13 @@ class Part
|
||||||
protected $name;
|
protected $name;
|
||||||
protected $type;
|
protected $type;
|
||||||
protected $nillable;
|
protected $nillable;
|
||||||
|
protected $minOccurs;
|
||||||
|
|
||||||
public function __construct($name, $type, $nillable = false)
|
public function __construct($name, $type, $nillable = false, $minOccurs = 1)
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
|
$this->minOccurs = $minOccurs;
|
||||||
$this->setNillable($nillable);
|
$this->setNillable($nillable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +52,16 @@ class Part
|
||||||
|
|
||||||
public function setNillable($nillable)
|
public function setNillable($nillable)
|
||||||
{
|
{
|
||||||
$this->nillable = (boolean) $nillable;
|
$this->nillable = (bool) $nillable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMinOccurs($minOccurs)
|
||||||
|
{
|
||||||
|
$this->minOccurs = $minOccurs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMinOccurs()
|
||||||
|
{
|
||||||
|
return $this->minOccurs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ class Dumper
|
||||||
protected $domService;
|
protected $domService;
|
||||||
protected $domPortType;
|
protected $domPortType;
|
||||||
|
|
||||||
public function __construct(Definition $definition, array $options = array())
|
public function __construct(Definition $definition, array $options = [])
|
||||||
{
|
{
|
||||||
$this->definition = $definition;
|
$this->definition = $definition;
|
||||||
$this->document = new \DOMDocument('1.0', 'utf-8');
|
$this->document = new \DOMDocument('1.0', 'utf-8');
|
||||||
|
@ -64,15 +64,15 @@ class Dumper
|
||||||
|
|
||||||
public function setOptions(array $options)
|
public function setOptions(array $options)
|
||||||
{
|
{
|
||||||
$this->options = array(
|
$this->options = [
|
||||||
'version11_class' => 'BeSimple\\SoapWsdl\\Dumper\\Version11',
|
'version11_class' => 'BeSimple\\SoapWsdl\\Dumper\\Version11',
|
||||||
'version12_class' => 'BeSimple\\SoapWsdl\\Dumper\\Version12',
|
'version12_class' => 'BeSimple\\SoapWsdl\\Dumper\\Version12',
|
||||||
'version11_name' => $this->definition->getName(),
|
'version11_name' => $this->definition->getName(),
|
||||||
'version12_name' => $this->definition->getName().'12',
|
'version12_name' => $this->definition->getName() . '12',
|
||||||
'stylesheet' => null,
|
'stylesheet' => null,
|
||||||
);
|
];
|
||||||
|
|
||||||
$invalid = array();
|
$invalid = [];
|
||||||
foreach ($options as $key => $value) {
|
foreach ($options as $key => $value) {
|
||||||
if (array_key_exists($key, $this->options)) {
|
if (array_key_exists($key, $this->options)) {
|
||||||
$this->options[$key] = $value;
|
$this->options[$key] = $value;
|
||||||
|
@ -114,7 +114,7 @@ class Dumper
|
||||||
$this->addMethods();
|
$this->addMethods();
|
||||||
$this->addService();
|
$this->addService();
|
||||||
|
|
||||||
foreach (array($this->version11, $this->version12) as $version) {
|
foreach ([$this->version11, $this->version12] as $version) {
|
||||||
if (!$version) {
|
if (!$version) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ class Dumper
|
||||||
protected function addService()
|
protected function addService()
|
||||||
{
|
{
|
||||||
$this->domService = $this->document->createElement('service');
|
$this->domService = $this->document->createElement('service');
|
||||||
$this->domService->setAttribute('name', $this->definition->getName().'Service');
|
$this->domService->setAttribute('name', $this->definition->getName() . 'Service');
|
||||||
|
|
||||||
$this->domDefinitions->appendChild($this->domService);
|
$this->domDefinitions->appendChild($this->domService);
|
||||||
|
|
||||||
|
@ -154,15 +154,15 @@ class Dumper
|
||||||
{
|
{
|
||||||
$this->domDefinitions = $this->document->createElement('definitions');
|
$this->domDefinitions = $this->document->createElement('definitions');
|
||||||
$this->domDefinitions->setAttributeNS(static::XML_NS_URI, static::XML_NS, static::WSDL_NS_URI);
|
$this->domDefinitions->setAttributeNS(static::XML_NS_URI, static::XML_NS, static::WSDL_NS_URI);
|
||||||
$this->domDefinitions->setAttributeNS(static::XML_NS_URI, static::XML_NS.':'.static::TYPES_NS, $this->definition->getNamespace());
|
$this->domDefinitions->setAttributeNS(static::XML_NS_URI, static::XML_NS . ':' . static::TYPES_NS, $this->definition->getNamespace());
|
||||||
$this->domDefinitions->setAttributeNS(static::XML_NS_URI, static::XML_NS.':'.static::SOAP_NS, static::SOAP_NS_URI);
|
$this->domDefinitions->setAttributeNS(static::XML_NS_URI, static::XML_NS . ':' . static::SOAP_NS, static::SOAP_NS_URI);
|
||||||
$this->domDefinitions->setAttributeNS(static::XML_NS_URI, static::XML_NS.':'.static::SOAP12_NS, static::SOAP12_NS_URI);
|
$this->domDefinitions->setAttributeNS(static::XML_NS_URI, static::XML_NS . ':' . static::SOAP12_NS, static::SOAP12_NS_URI);
|
||||||
$this->domDefinitions->setAttributeNS(static::XML_NS_URI, static::XML_NS.':'.static::XSD_NS, static::XSD_NS_URI);
|
$this->domDefinitions->setAttributeNS(static::XML_NS_URI, static::XML_NS . ':' . static::XSD_NS, static::XSD_NS_URI);
|
||||||
$this->domDefinitions->setAttributeNS(static::XML_NS_URI, static::XML_NS.':'.static::SOAP_ENC_NS, static::SOAP_ENC_URI);
|
$this->domDefinitions->setAttributeNS(static::XML_NS_URI, static::XML_NS . ':' . static::SOAP_ENC_NS, static::SOAP_ENC_URI);
|
||||||
$this->domDefinitions->setAttributeNS(static::XML_NS_URI, static::XML_NS.':'.static::WSDL_NS, static::WSDL_NS_URI);
|
$this->domDefinitions->setAttributeNS(static::XML_NS_URI, static::XML_NS . ':' . static::WSDL_NS, static::WSDL_NS_URI);
|
||||||
|
|
||||||
foreach ($this->definition->getTypeRepository()->getXmlNamespaces() as $prefix => $uri) {
|
foreach ($this->definition->getTypeRepository()->getXmlNamespaces() as $prefix => $uri) {
|
||||||
$this->domDefinitions->setAttributeNs(static::XML_NS_URI, static::XML_NS.':'.$prefix, $uri);
|
$this->domDefinitions->setAttributeNs(static::XML_NS_URI, static::XML_NS . ':' . $prefix, $uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->domDefinitions->setAttribute('name', $this->definition->getName());
|
$this->domDefinitions->setAttribute('name', $this->definition->getName());
|
||||||
|
@ -203,7 +203,7 @@ class Dumper
|
||||||
$partElement->setAttribute('name', $part->getName());
|
$partElement->setAttribute('name', $part->getName());
|
||||||
|
|
||||||
if ($type instanceof ComplexType) {
|
if ($type instanceof ComplexType) {
|
||||||
$partElement->setAttribute('type', static::TYPES_NS.':'.$type->getXmlType());
|
$partElement->setAttribute('type', static::TYPES_NS . ':' . $type->getXmlType());
|
||||||
} else {
|
} else {
|
||||||
$partElement->setAttribute('type', $type);
|
$partElement->setAttribute('type', $type);
|
||||||
}
|
}
|
||||||
|
@ -220,7 +220,7 @@ class Dumper
|
||||||
$types = $this->document->createElement('types');
|
$types = $this->document->createElement('types');
|
||||||
$this->domDefinitions->appendChild($types);
|
$this->domDefinitions->appendChild($types);
|
||||||
|
|
||||||
$this->domSchema = $this->document->createElement(static::XSD_NS.':schema');
|
$this->domSchema = $this->document->createElement(static::XSD_NS . ':schema');
|
||||||
$this->domSchema->setAttribute('targetNamespace', $this->definition->getNamespace());
|
$this->domSchema->setAttribute('targetNamespace', $this->definition->getNamespace());
|
||||||
$types->appendChild($this->domSchema);
|
$types->appendChild($this->domSchema);
|
||||||
|
|
||||||
|
@ -233,16 +233,16 @@ class Dumper
|
||||||
|
|
||||||
protected function addComplexType(ComplexType $type)
|
protected function addComplexType(ComplexType $type)
|
||||||
{
|
{
|
||||||
$complexType = $this->document->createElement(static::XSD_NS.':complexType');
|
$complexType = $this->document->createElement(static::XSD_NS . ':complexType');
|
||||||
$complexType->setAttribute('name', $type->getXmlType());
|
$complexType->setAttribute('name', $type->getXmlType());
|
||||||
|
|
||||||
$all = $this->document->createElement(static::XSD_NS.':'.($type instanceof ArrayOfType ? 'sequence' : 'all'));
|
$all = $this->document->createElement(static::XSD_NS . ':' . ($type instanceof ArrayOfType ? 'sequence' : 'all'));
|
||||||
$complexType->appendChild($all);
|
$complexType->appendChild($all);
|
||||||
|
|
||||||
foreach ($type->all() as $child) {
|
foreach ($type->all() as $child) {
|
||||||
$childType = $this->definition->getTypeRepository()->getType($child->getType());
|
$childType = $this->definition->getTypeRepository()->getType($child->getType());
|
||||||
|
|
||||||
$element = $this->document->createElement(static::XSD_NS.':element');
|
$element = $this->document->createElement(static::XSD_NS . ':element');
|
||||||
$element->setAttribute('name', $child->getName());
|
$element->setAttribute('name', $child->getName());
|
||||||
|
|
||||||
if ($childType instanceof ComplexType) {
|
if ($childType instanceof ComplexType) {
|
||||||
|
@ -251,7 +251,7 @@ class Dumper
|
||||||
$name = $childType->getName();
|
$name = $childType->getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
$element->setAttribute('type', static::TYPES_NS.':'.$name);
|
$element->setAttribute('type', static::TYPES_NS . ':' . $name);
|
||||||
} else {
|
} else {
|
||||||
$element->setAttribute('type', $childType);
|
$element->setAttribute('type', $childType);
|
||||||
}
|
}
|
||||||
|
@ -265,6 +265,12 @@ class Dumper
|
||||||
$element->setAttribute('maxOccurs', 'unbounded');
|
$element->setAttribute('maxOccurs', 'unbounded');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 1 is the default value of minOccurs.
|
||||||
|
if (1 != $child->getMinOccurs()) {
|
||||||
|
$element->setAttribute('minOccurs', $child->getMinOccurs());
|
||||||
|
$element->setAttribute('maxOccurs', 'unbounded');
|
||||||
|
}
|
||||||
|
|
||||||
$all->appendChild($element);
|
$all->appendChild($element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +280,7 @@ class Dumper
|
||||||
protected function addPortType()
|
protected function addPortType()
|
||||||
{
|
{
|
||||||
$this->domPortType = $this->document->createElement('portType');
|
$this->domPortType = $this->document->createElement('portType');
|
||||||
$this->domPortType->setAttribute('name', $this->definition->getName().'PortType');
|
$this->domPortType->setAttribute('name', $this->definition->getName() . 'PortType');
|
||||||
|
|
||||||
$this->domDefinitions->appendChild($this->domPortType);
|
$this->domDefinitions->appendChild($this->domPortType);
|
||||||
}
|
}
|
||||||
|
@ -284,13 +290,13 @@ class Dumper
|
||||||
$operation = $this->document->createElement('operation');
|
$operation = $this->document->createElement('operation');
|
||||||
$operation->setAttribute('name', $method->getName());
|
$operation->setAttribute('name', $method->getName());
|
||||||
|
|
||||||
foreach (array('input' => $method->getInput(), 'output' => $method->getOutput(), 'fault' => $method->getFault()) as $type => $message) {
|
foreach (['input' => $method->getInput(), 'output' => $method->getOutput(), 'fault' => $method->getFault()] as $type => $message) {
|
||||||
if ('fault' === $type && $message->isEmpty()) {
|
if ('fault' === $type && $message->isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$node = $this->document->createElement($type);
|
$node = $this->document->createElement($type);
|
||||||
$node->setAttribute('message', static::TYPES_NS.':'.$message->getName());
|
$node->setAttribute('message', static::TYPES_NS . ':' . $message->getName());
|
||||||
|
|
||||||
$operation->appendChild($node);
|
$operation->appendChild($node);
|
||||||
}
|
}
|
||||||
|
@ -326,7 +332,7 @@ class Dumper
|
||||||
static::TYPES_NS,
|
static::TYPES_NS,
|
||||||
$this->options['version11_name'],
|
$this->options['version11_name'],
|
||||||
$this->definition->getNamespace(),
|
$this->definition->getNamespace(),
|
||||||
static::TYPES_NS.':'.$this->definition->getName().'PortType',
|
static::TYPES_NS . ':' . $this->definition->getName() . 'PortType',
|
||||||
$this->definition->getOption('location'),
|
$this->definition->getOption('location'),
|
||||||
$this->definition->getOption('style')
|
$this->definition->getOption('style')
|
||||||
);
|
);
|
||||||
|
@ -343,7 +349,7 @@ class Dumper
|
||||||
static::TYPES_NS,
|
static::TYPES_NS,
|
||||||
$this->options['version12_name'],
|
$this->options['version12_name'],
|
||||||
$this->definition->getNamespace(),
|
$this->definition->getNamespace(),
|
||||||
static::TYPES_NS.':'.$this->definition->getName().'PortType',
|
static::TYPES_NS . ':' . $this->definition->getName() . 'PortType',
|
||||||
$this->definition->getOption('location'),
|
$this->definition->getOption('location'),
|
||||||
$this->definition->getOption('style')
|
$this->definition->getOption('style')
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue