diff --git a/template/types/methods/constructors/default.php b/template/types/methods/constructors/default.php index 11a00cf3..394d4c5f 100644 --- a/template/types/methods/constructors/default.php +++ b/template/types/methods/constructors/default.php @@ -56,7 +56,11 @@ public function __construct(null|arrayisValueContainer()) : ?>| } } - $value) { +isOverloaded()) { continue; } @@ -66,6 +70,7 @@ public function __construct(null|arrayisValueContainer()) : ?>| [ 'config' => $config, 'type' => $type, + 'propertyIndex' => $propertyIndex, 'property' => $property, ] ); @@ -75,10 +80,14 @@ public function __construct(null|arrayisValueContainer()) : ?>| [ 'config' => $config, 'type' => $type, + 'propertyIndex' => $propertyIndex, 'property' => $property ] ); endif; + $propertyIndex++; endforeach; ?> + + } } getValueFHIRType(); $fieldConstantName = $property->getFieldConstantName(); $requireArgs = [ 'config' => $config, + 'propertyIndex' => $propertyIndex, 'property' => $property ]; diff --git a/template/types/methods/constructors/primitive_container.php b/template/types/methods/constructors/primitive_container.php index 44988235..91b981e8 100644 --- a/template/types/methods/constructors/primitive_container.php +++ b/template/types/methods/constructors/primitive_container.php @@ -59,7 +59,9 @@ public function __construct(_addFHIRComment($data[PHPFHIRConstants::JSON_FIELD_FHIR_COMMENTS]); } } -isOverloaded()) : continue; endif; @@ -68,9 +70,12 @@ public function __construct( $config, 'type' => $type, + 'propertyIndex' => $propertyIndex, 'property' => $property, ] ); + $propertyIndex++; endforeach; ?> + } getValueFHIRType()->getClassName(); $propertyFieldConst = $property->getFieldConstantName(); $propertyFieldConstExt = $property->getFieldConstantExtensionName(); $setter = $property->getSetterName(); -ob_start(); ?> - if (array_key_exists(self::, $data)) { +ob_start(); +if (0 === $propertyIndex) : ?> + if else if (self:: === $field) { isCollection()) : ?> - if (is_array($data[self::])) { - foreach($data[self::] as $v) { - if ($v instanceof ) { - $this->($v); - } else { - $this->(new ($v)); + if (is_array($value)) { + foreach($value as $v) { + if ($v instanceof ) { + $this->($v); + } else { + $this->(new ($v)); + } } + } elseif ($value instanceof ) { + $this->($value); + } else { + $this->(new ($value)); } - } elseif ($data[self::] instanceof ) { - $this->($data[self::]); - } else { - $this->(new ($data[self::])); - } - if ($data[self::] instanceof ) { - $this->($data[self::]); - } else { - $this->(new ($data[self::])); - } + if ($value instanceof ) { + $this->($value); + } else { + $this->(new ($value)); + } - } - diff --git a/template/types/methods/constructors/property_setter_primitive.php b/template/types/methods/constructors/property_setter_primitive.php index af9b9700..62d2061f 100644 --- a/template/types/methods/constructors/property_setter_primitive.php +++ b/template/types/methods/constructors/property_setter_primitive.php @@ -16,33 +16,35 @@ * limitations under the License. */ +/** @var \DCarbone\PHPFHIR\Config $config */ /** @var \DCarbone\PHPFHIR\Definition\Property $property */ +/** @var int $propertyIndex */ $propertyFieldConst = $property->getFieldConstantName(); $setter = $property->getSetterName(); -ob_start(); ?> - if (array_key_exists(self::, $data)) { +ob_start(); +if (0 === $propertyIndex) : ?> + if else if (self:: === $field) { isCollection()) : ?> - if (is_array($data[self::])) { - foreach($data[self::] as $v) { - if (!($v instanceof getValueFHIRType()->getClassName(); ?>)) { - $v = new getValueFHIRType()->getClassName(); ?>($v); + if (is_array($value)) { + foreach($value as $v) { + if (!($v instanceof getValueFHIRType()->getClassName(); ?>)) { + $v = new getValueFHIRType()->getClassName(); ?>($v); + } + $this->($v); } - $this->($v); + } else if ($value instanceof getValueFHIRType()->getClassName(); ?>) { + $this->($data[self::]); + } else { + $this->(new getValueFHIRType()->getClassName(); ?>($value)); } - } else if ($data[self::] instanceof getValueFHIRType()->getClassName(); ?>) { - $this->($data[self::]); - } else { - $this->(new getValueFHIRType()->getClassName(); ?>($data[self::])); - } - if ($data[self::] instanceof getvalueFHIRType()->getClassName(); ?>) { - $this->($data[self::]); - } else { - $this->(new getValueFHIRType()->getClassName(); ?>($data[self::])); - } + if ($value instanceof getvalueFHIRType()->getClassName(); ?>) { + $this->($value); + } else { + $this->(new getValueFHIRType()->getClassName(); ?>($value)); + } - } -getValueFHIRType()->getClassName(); $propertyFieldConst = $property->getFieldConstantName(); @@ -26,42 +27,43 @@ // these types are a pain in the ass -ob_start(); ?> - if (array_key_exists(self::, $data) || array_key_exists(self::, $data)) { - $value = $data[self::] ?? null; - $ext = (isset($data[self::]) && is_array($data[self::])) ? $data[self::] : []; - if (null !== $value) { - if ($value instanceof ) { - $this->($value); - } else isCollection()) : ?>if (is_array($value)) { - foreach($value as $i => $v) { - if ($v instanceof ) { - $this->($v); - } else { - $iext = (isset($ext[$i]) && is_array($ext[$i])) ? $ext[$i] : []; - if (is_array($v)) { - $this->(new (array_merge($v, $iext))); +ob_start(); +if (0 === $propertyIndex) : ?> + if else if ((self:: === $field || self:: === $field) && !isset($_parsed[self::])) { + $value = $data[self::] ?? null; + $ext = (isset($data[self::]) && is_array($data[self::])) ? $data[self::] : []; + if (null !== $value) { + if ($value instanceof ) { + $this->($value); + } else isCollection()) : ?>if (is_array($value)) { + foreach($value as $i => $v) { + if ($v instanceof ) { + $this->($v); } else { - $this->(new ([::FIELD_VALUE => $v] + $iext)); + $iext = (isset($ext[$i]) && is_array($ext[$i])) ? $ext[$i] : []; + if (is_array($v)) { + $this->(new (array_merge($v, $iext))); + } else { + $this->(new ([::FIELD_VALUE => $v] + $iext)); + } } } + } elseif (is_array($value)) { + $this->(new (array_merge($ext, $value))); + } else { + $this->(new ([::FIELD_VALUE => $value] + $ext)); } - } elseif (is_array($value)) { - $this->(new (array_merge($ext, $value))); - } else { - $this->(new ([::FIELD_VALUE => $value] + $ext)); - } - } elseif ([] !== $ext) { + } elseif ([] !== $ext) { isCollection()) : ?> - foreach($ext as $iext) { - $this->(new ($iext)); - } + foreach($ext as $iext) { + $this->(new ($iext)); + } - $this->(new ($ext)); + $this->(new ($ext)); - } else { - $this->(new (null)); - } - } -(new (null)); + } + $_parsed[self::] = true; + } diff --git a/template/types/methods/constructors/resource_container_property_setter_call.php b/template/types/methods/constructors/resource_container_property_setter_call.php index e59d9c99..f0b92387 100644 --- a/template/types/methods/constructors/resource_container_property_setter_call.php +++ b/template/types/methods/constructors/resource_container_property_setter_call.php @@ -18,6 +18,7 @@ /** @var \DCarbone\PHPFHIR\Definition\Type $type */ /** @var \DCarbone\PHPFHIR\Definition\Property $property */ +/** @var int $propertyIndex */ $typeClassName = $type->getClassName(); $propertyName = $property->getName(); @@ -25,51 +26,51 @@ $propertyType = $property->getValueFHIRType(); $setter = ($property->isCollection() ? 'add' : 'set') . ucfirst($propertyName); -ob_start(); ?> - if (isset($data[self::])) { +ob_start(); +if (0 === $propertyIndex) : ?> + if else if (self:: === $field) { isCollection()) : ?> - if (is_array($data[self::])) { - if (is_int(key($data[self::]))) { - $this->set($data[self::]); - } else { - $typeClass = PHPFHIRTypeMap::getContainedTypeFromArray($data[self::]); + if (is_array($value)) { + if (is_int(key($value))) { + $this->set($value); + } else { + $typeClass = PHPFHIRTypeMap::getContainedTypeFromArray($value); + if (null === $typeClass) { + throw new \InvalidArgumentException(sprintf( + ' - Unable to determine class for field "" from value: %s', + json_encode($value) + )); + } + $this->(new $typeClass($value)); + } + } elseif ($value instanceof ) { + $this->($value); + } + + if (is_object($value)) { + if ($value instanceof ) { + $this->($value); + } else { + throw new \InvalidArgumentException(sprintf( + ' - Field "" must be an object implementing , object of type %s seen', + get_class($value) + )); + } + } elseif (is_array($value)) { + $typeClass = PHPFHIRTypeMap::getContainedTypeFromArray($value); if (null === $typeClass) { throw new \InvalidArgumentException(sprintf( ' - Unable to determine class for field "" from value: %s', - json_encode($data[self::]) + json_encode($value) )); } - $this->(new $typeClass($data[self::])); - } - } elseif ($data[self::] instanceof ) { - $this->($data[self::]); - } - - if (is_object($data[self::])) { - if ($data[self::] instanceof ) { - $this->($data[self::]); + $this->(new $typeClass($value)); } else { - throw new \InvalidArgumentException(sprintf( - ' - Field "" must be an object implementing , object of type %s seen', - get_class($data[self::]) - )); - } - } elseif (is_array($data[self::])) { - $typeClass = PHPFHIRTypeMap::getContainedTypeFromArray($data[self::]); - if (null === $typeClass) { throw new \InvalidArgumentException(sprintf( ' - Unable to determine class for field "" from value: %s', - json_encode($data[self::]) + json_encode($value) )); } - $this->(new $typeClass($data[self::])); - } else { - throw new \InvalidArgumentException(sprintf( - ' - Unable to determine class for field "" from value: %s', - json_encode($data[self::]) - )); - } - } -