Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with "item" for collection of objects #2

Merged
merged 12 commits into from
Sep 12, 2016
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@ private function processType($phpType, $message)

$message = $array;
} else {
$message = $this->checkComplexType($phpType, $message);
if (is_array($message)) {
foreach ($message as $complexType) {
$array[] = $this->checkComplexType($phpType, $complexType);
}
$message = $array;
} else {
$message = $this->checkComplexType($phpType, $message);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class ComplexType extends Configuration
private $name;
private $value;
private $isNillable = false;
private $minOccurs;
private $maxOccurs;

public function getName()
{
Expand Down Expand Up @@ -49,8 +51,28 @@ public function setNillable($isNillable)
$this->isNillable = (bool) $isNillable;
}

public function getMinOccurs()
{
return $this->minOccurs;
}

public function setMinOccurs($minOccurs)
{
$this->minOccurs = $minOccurs;
}

public function getMaxOccurs()
{
return $this->maxOccurs;
}

public function setMaxOccurs($maxOccurs)
{
$this->maxOccurs = $maxOccurs;
}

public function getAliasName()
{
return 'complextype';
}
}
}
21 changes: 21 additions & 0 deletions src/BeSimple/SoapBundle/ServiceDefinition/ComplexType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class ComplexType
private $name;
private $value;
private $isNillable = false;
private $minOccurs;
private $maxOccurs;

public function getName()
{
Expand Down Expand Up @@ -50,4 +52,23 @@ public function setNillable($isNillable)
{
$this->isNillable = (bool) $isNillable;
}

public function getMinOccurs()
{
return $this->minOccurs;
}

public function setMinOccurs($minOccurs)
{
$this->minOccurs = $minOccurs;
}
public function getMaxOccurs()
{
return $this->maxOccurs;
}

public function setMaxOccurs($maxOccurs)
{
$this->maxOccurs = $maxOccurs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private function loadType($phpType)
$loaded = $complexTypeResolver->load($phpType);
$complexType = new ComplexType($phpType, isset($loaded['alias']) ? $loaded['alias'] : $phpType);
foreach ($loaded['properties'] as $name => $property) {
$complexType->add($name, $this->loadType($property->getValue()), $property->isNillable());
$complexType->add($name, $this->loadType($property->getValue()), $property->isNillable(), $property->getMinOccurs(), $property->getMaxOccurs());
}

$this->typeRepository->addComplexType($complexType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public function load($class, $type = null)
$propertyComplexType = new ComplexType();
$propertyComplexType->setValue($complexType->getValue());
$propertyComplexType->setNillable($complexType->isNillable());
$propertyComplexType->setMinOccurs($complexType->getMinOccurs());
$propertyComplexType->setMaxOccurs($complexType->getMaxOccurs());
$propertyComplexType->setName($property->getName());
$annotations['properties']->add($propertyComplexType);
}
Expand Down
4 changes: 2 additions & 2 deletions src/BeSimple/SoapCommon/Definition/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public function isEmpty()
return 0 === count($this->parts) ? true : false;
}

public function add($name, $phpType, $nillable = false)
public function add($name, $phpType, $nillable = false, $minOccurs = null, $maxOccurs = null)
{
if ($phpType instanceof TypeInterface) {
$phpType = $phpType->getPhpType();
}

$this->parts[$name] = new Part($name, $phpType, $nillable);
$this->parts[$name] = new Part($name, $phpType, $nillable, $minOccurs, $maxOccurs);

return $this;
}
Expand Down
26 changes: 25 additions & 1 deletion src/BeSimple/SoapCommon/Definition/Part.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ class Part
protected $name;
protected $type;
protected $nillable;
protected $minOccurs;
protected $maxOccurs;

public function __construct($name, $type, $nillable = false)
public function __construct($name, $type, $nillable = false, $minOccurs = null, $maxOccurs = null)
{
$this->name = $name;
$this->type = $type;
$this->setNillable($nillable);
$this->setMinOccurs($minOccurs);
$this->setNillable($maxOccurs);
}

public function getName()
Expand All @@ -52,4 +56,24 @@ public function setNillable($nillable)
{
$this->nillable = (boolean) $nillable;
}

public function getMinOccurs()
{
return $this->minOccurs;
}

public function setMinOccurs($minOccurs)
{
$this->minOccurs = $minOccurs;
}

public function getMaxOccurs()
{
return $this->maxOccurs;
}

public function setMaxOccurs($maxOccurs)
{
$this->maxOccurs = $maxOccurs;
}
}
7 changes: 7 additions & 0 deletions src/BeSimple/SoapWsdl/Dumper/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ protected function addComplexType(ComplexType $type)
if ($child->isNillable()) {
$element->setAttribute('nillable', 'true');
}

if (null !== $child->getMinOccurs() && 1 != $child->getMinOccurs()) {
$element->setAttribute('minOccurs', $child->getMinOccurs());
}
if (null !== $child->getMaxOccurs() && 1 != $child->getMaxOccurs()) {
$element->setAttribute('maxOccurs', $child->getMaxOccurs());
}

if ($type instanceof ArrayOfType) {
$element->setAttribute('minOccurs', 0);
Expand Down