Skip to content

Commit

Permalink
Merge pull request #1 from MiWayInsurance/feature/arrayOfType-item-re…
Browse files Browse the repository at this point in the history
…move

Feature - removing the "item" object type and using the actual object type for arrays
  • Loading branch information
pierredup authored Sep 17, 2018
2 parents 27ebf0f + 7188d49 commit 8476fcc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor/
composer.lock
phpunit.xml
.idea/*
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,24 @@ public function processMessage(Method $messageDefinition, $message, TypeReposito
protected function processType($phpType, $message)
{
$isArray = false;
$arrayOfTypeName = '';

$type = $this->typeRepository->getType($phpType);
if ($type instanceof ArrayOfType) {
$isArray = true;
$array = array();
$arrayOfTypeName = str_replace('ArrayOf', '', $type->getXmlType());

$type = $this->typeRepository->getType($type->get('item')->getType());
$type = $this->typeRepository->getType($type->get($arrayOfTypeName)->getType());
}

// @TODO Fix array reference
if ($type instanceof ComplexType) {
$phpType = $type->getPhpType();

if ($isArray) {
if (isset($message->item)) {
foreach ($message->item as $complexType) {
if (isset($message->{$arrayOfTypeName})) {
foreach ($message->{$arrayOfTypeName} as $complexType) {
$array[] = $this->checkComplexType($phpType, $complexType);
}

Expand All @@ -84,8 +86,8 @@ protected function processType($phpType, $message)
$message = $this->checkComplexType($phpType, $message);
}
} elseif ($isArray) {
if (isset($message->item)) {
$message = $message->item;
if (isset($message->{$arrayOfTypeName})) {
$message = $message->{$arrayOfTypeName};
} else {
$message = $array;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ private function processType($phpType, $message)
$type = $this->typeRepository->getType($phpType);
if ($type instanceof ArrayOfType) {
$isArray = true;
$arrayOfTypeName = str_replace('ArrayOf', '', $type->getXmlType());

$type = $this->typeRepository->getType($type->get('item')->getType());
$type = $this->typeRepository->getType($type->get($arrayOfTypeName)->getType());
}

if ($type instanceof ComplexType) {
Expand Down
2 changes: 1 addition & 1 deletion src/BeSimple/SoapCommon/Definition/Type/ArrayOfType.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public function __construct($phpType, $arrayOf, $xmlTypeOf)

parent::__construct($phpType, 'ArrayOf'.ucfirst($xmlTypeOf ?: $arrayOf));

$this->add('item', $arrayOf);
$this->add($xmlTypeOf, $arrayOf);
}
}

0 comments on commit 8476fcc

Please sign in to comment.