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 $value;
private $isNillable = false;
private $minOccurs = 1;
public function getName()
{
@ -59,6 +60,16 @@ class ComplexType extends Configuration
$this->isNillable = (bool) $isNillable;
}
public function setMinOccurs($minOccurs)
{
$this->minOccurs = $minOccurs;
}
public function getMinOccurs()
{
return $this->minOccurs;
}
public function getAliasName()
{
return 'complextype';

View File

@ -20,6 +20,7 @@ class ComplexType
private $name;
private $value;
private $isNillable = false;
private $minOccurs = 1;
public function getName()
{
@ -50,4 +51,14 @@ class ComplexType
{
$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));
}
$annotations = array();
$annotations = [];
$class = new \ReflectionClass($class);
if ($alias = $this->reader->getClassAnnotation($class, $this->aliasClass)) {
@ -59,6 +59,7 @@ class AnnotationComplexTypeLoader extends AnnotationClassLoader
$propertyComplexType->setValue($complexType->getValue());
$propertyComplexType->setNillable($complexType->isNillable());
$propertyComplexType->setName($property->getName());
$propertyComplexType->setMinOccurs($complexType->getMinOccurs());
$annotations['properties']->add($propertyComplexType);
}
}
@ -72,7 +73,7 @@ class AnnotationComplexTypeLoader extends AnnotationClassLoader
* @param mixed $resource A resource
* @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)
{

View File

@ -25,7 +25,7 @@ class Message
public function __construct($name)
{
$this->name = $name;
$this->parts = array();
$this->parts = [];
}
public function getName()
@ -48,13 +48,13 @@ class Message
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) {
$phpType = $phpType->getPhpType();
}
$this->parts[$name] = new Part($name, $phpType, $nillable);
$this->parts[$name] = new Part($name, $phpType, $nillable, $minOccurs);
return $this;
}

View File

@ -20,11 +20,13 @@ class Part
protected $name;
protected $type;
protected $nillable;
protected $minOccurs;
public function __construct($name, $type, $nillable = false)
public function __construct($name, $type, $nillable = false, $minOccurs = 1)
{
$this->name = $name;
$this->type = $type;
$this->minOccurs = $minOccurs;
$this->setNillable($nillable);
}
@ -50,6 +52,16 @@ class Part
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 $domPortType;
public function __construct(Definition $definition, array $options = array())
public function __construct(Definition $definition, array $options = [])
{
$this->definition = $definition;
$this->document = new \DOMDocument('1.0', 'utf-8');
@ -64,15 +64,15 @@ class Dumper
public function setOptions(array $options)
{
$this->options = array(
$this->options = [
'version11_class' => 'BeSimple\\SoapWsdl\\Dumper\\Version11',
'version12_class' => 'BeSimple\\SoapWsdl\\Dumper\\Version12',
'version11_name' => $this->definition->getName(),
'version12_name' => $this->definition->getName() . '12',
'stylesheet' => null,
);
];
$invalid = array();
$invalid = [];
foreach ($options as $key => $value) {
if (array_key_exists($key, $this->options)) {
$this->options[$key] = $value;
@ -114,7 +114,7 @@ class Dumper
$this->addMethods();
$this->addService();
foreach (array($this->version11, $this->version12) as $version) {
foreach ([$this->version11, $this->version12] as $version) {
if (!$version) {
continue;
}
@ -265,6 +265,12 @@ class Dumper
$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);
}
@ -284,7 +290,7 @@ class Dumper
$operation = $this->document->createElement('operation');
$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()) {
continue;
}