Merge pull request #4 from Cadoles/develop

Add minOccurs annotation support on complexType
This commit is contained in:
Mimir 2020-07-15 16:29:05 +02:00 committed by GitHub
commit 9f7b7f40b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 74 additions and 33 deletions

View File

@ -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()
{ {
@ -59,6 +60,16 @@ class ComplexType extends Configuration
$this->isNillable = (bool) $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';

View File

@ -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;
}
} }

View File

@ -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)
{ {

View File

@ -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;
} }

View File

@ -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;
} }
} }

View File

@ -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;
} }
@ -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);
} }
@ -284,7 +290,7 @@ 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;
} }