Skip to content

Commit

Permalink
more named param work
Browse files Browse the repository at this point in the history
  • Loading branch information
dcarbone committed Jan 8, 2025
1 parent 30a6185 commit 5ed590e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
29 changes: 24 additions & 5 deletions src/Version/Definition/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,19 +379,38 @@ public function hasPropertiesWithValidations(): bool
*/
public function getAllPropertiesIndexedIterator(): iterable
{
$properties = [];
$p = [];
foreach ($this->getParentTypes() as $parentType) {
foreach ($parentType->getProperties()->getGenerator() as $property) {
if (!isset($properties[$property->getName()])) {
$properties[$property->getName()] = $property;
if (!isset($p[$property->getName()])) {
$p[$property->getName()] = $property;
}
}
}
foreach ($this->getProperties()->getGenerator() as $property) {
$properties[$property->getName()] = $property;
$p[$property->getName()] = $property;
}
// this returns an \SplFixedArray to provide an indexed iterator
return \SplFixedArray::fromArray($properties, preserveKeys: false);
return \SplFixedArray::fromArray($p, preserveKeys: false);
}

/**
* Returns an indexed iterator containing all properties defined on parents of this type. Locally overloaded
* properties are omitted.
*
* @return \DCarbone\PHPFHIR\Version\Definition\Property[]
*/
public function getParentPropertiesIterator(): iterable
{
$p = [];
foreach ($this->getParentTypes() as $parentType) {
foreach ($parentType->getProperties()->getGenerator() as $property) {
if (!$this->_properties->hasProperty($property->getName()) && !isset($p[$property->getName()])) {
$p[$property->getName()] = $property;
}
}
}
return \SplFixedArray::fromArray($p, preserveKeys: false);
}

/**
Expand Down
25 changes: 19 additions & 6 deletions template/versions/types/methods/constructor.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,23 @@ public function __construct(<?php echo TypeHintUtils::typeSetterTypeHint($versio
?>
* @param <?php echo TypeHintUtils::propertySetterTypeHint($version, $property, true); ?> $<?php echo $property->getName(); ?>

<?php endforeach; ?> */
<?php endforeach; if ($type->hasCommentContainerParent() || $type->isCommentContainer()) : ?>
* @param null|array $fhirComments
<?php endif; ?> */
public function __construct(null|array $data = null,
<?php echo TypeHintUtils::propertySetterTypeHint($version, $valueProperty, true); ?> $value = null<?php foreach($type->getAllPropertiesIndexedIterator() as $property) :
if ($property->isValueProperty()) {
continue;
}
?>,
<?php echo TypeHintUtils::propertySetterTypeHint($version, $property, true); ?> $<?php echo $property->getName(); ?> = null<?php endforeach; ?>)
<?php echo TypeHintUtils::propertySetterTypeHint($version, $property, true); ?> $<?php echo $property->getName(); ?> = null<?php endforeach; if ($type->hasCommentContainerParent() || $type->isCommentContainer()) : ?>,
null|array $fhirComments = null<?php endif; ?>)
{
<?php if (null !== $parentType) : ?>
parent::__construct(data: $data<?php foreach($type->getParentPropertiesIterator() as $property) : ?>,
<?php echo $property->getName(); ?>: $<?php echo $property->getName(); ?><?php endforeach; ?><?php if ($type->hasCommentContainerParent()) : ?>,
fhirComments: $fhirComments<?php endif; ?>);
<?php endif; ?>
if (null === $data) {
return;
}
Expand All @@ -116,7 +124,9 @@ public function __construct(null|array $data = null,
parent::__construct($data);
<?php endif; ?><?php if (!$type->hasCommentContainerParent() && $type->isCommentContainer()) : ?>

if (isset($data[<?php echo PHPFHIR_CLASSNAME_CONSTANTS; ?>::JSON_FIELD_FHIR_COMMENTS])) {
if (null !== $fhirComments && [] !== $fhirComments) {
$this->_setFHIRComments($fhirComments);
} else if (isset($data[<?php echo PHPFHIR_CLASSNAME_CONSTANTS; ?>::JSON_FIELD_FHIR_COMMENTS])) {
if (is_array($data[<?php echo PHPFHIR_CLASSNAME_CONSTANTS; ?>::JSON_FIELD_FHIR_COMMENTS])) {
$this->_setFHIRComments($data[<?php echo PHPFHIR_CLASSNAME_CONSTANTS; ?>::JSON_FIELD_FHIR_COMMENTS]);
} elseif (is_string($data[<?php echo PHPFHIR_CLASSNAME_CONSTANTS; ?>::JSON_FIELD_FHIR_COMMENTS])) {
Expand All @@ -137,6 +147,7 @@ public function __construct(null|array $data = null,
endforeach; ?>
}
<?php else : ?>

/**
* <?php echo $typeClassName; ?> Constructor
* @param null|array $data
Expand All @@ -152,16 +163,18 @@ public function __construct(null|array $data = null,
?>
* @param <?php echo TypeHintUtils::propertySetterTypeHint($version, $property, true); ?> $<?php echo $property->getName(); ?>

<?php endforeach; ?> */
<?php endforeach; if ($type->hasCommentContainerParent() && $type->isCommentContainer()) : ?>
* @param null|array $fhirComments
<?php endif; ?> */
public function __construct(null|array $data = null<?php if ($type->isValueContainer()) : ?>,
<?php echo TypeHintUtils::propertySetterTypeHint($version, $valueProperty, true);?> $value = null<?php endif; ?>
<?php foreach($type->getAllPropertiesIndexedIterator() as $property) :
if ($type->isValueContainer() && $property->isValueProperty()) {
continue;
}
?>,
<?php echo TypeHintUtils::propertySetterTypeHint($version, $property, true); ?> $<?php echo $property->getName(); ?>
<?php endforeach; ?>)
<?php echo TypeHintUtils::propertySetterTypeHint($version, $property, true); ?> $<?php echo $property->getName(); ?> = null<?php endforeach; if ($type->hasCommentContainerParent() && $type->isCommentContainer()) : ?>,
null|array $fhirComments = null<?php endif; ?>)
{
if (null === $data || [] === $data) {
<?php if ($type->hasParent()) : ?>
Expand Down

0 comments on commit 5ed590e

Please sign in to comment.