diff --git a/src/Builder/TypeBuilder.php b/src/Builder/TypeBuilder.php index b8dbd969..5c34fabb 100644 --- a/src/Builder/TypeBuilder.php +++ b/src/Builder/TypeBuilder.php @@ -60,7 +60,7 @@ private static function buildPrimitiveType(Config $config, $type = self::buildDefaultType($config, $version, $fhirName, $sxe, $sourceFilename); $value = new Property($type, $sxe, $sourceFilename); $value->setName(PHPFHIR_VALUE_PROPERTY_NAME); - $type->getLocalProperties()->addProperty($value); + $type->getProperties()->addProperty($value); return $type; } diff --git a/src/Utilities/ImportUtils.php b/src/Utilities/ImportUtils.php index 3abe755e..d40efeb1 100644 --- a/src/Utilities/ImportUtils.php +++ b/src/Utilities/ImportUtils.php @@ -45,9 +45,6 @@ public static function buildVersionTypeImports(Type $type): void // immediately add self $imports->addImport($type->getFullyQualifiedNamespace(false), $type->getClassName()); - $typeNS = $type->getFullyQualifiedNamespace(false); - $configNS = $type->getConfig()->getFullyQualifiedName(false); - $typeKind = $type->getKind(); if (!$type->isAbstract()) { @@ -106,15 +103,14 @@ public static function buildVersionTypeImports(Type $type): void continue; } - if ($ptk->isOneOf(TypeKindEnum::RESOURCE_CONTAINER, TypeKindEnum::RESOURCE_INLINE) && - $typeNS !== $configNS) { + if ($ptk->isOneOf(TypeKindEnum::RESOURCE_CONTAINER, TypeKindEnum::RESOURCE_INLINE)) { $imports->addCoreFileImportsByName(PHPFHIR_CLASSNAME_CONSTANTS); $imports->addVersionCoreFileImportsByName($type->getVersion(), PHPFHIR_INTERFACE_VERSION_CONTAINED_TYPE); $imports->addVersionCoreFileImportsByName($type->getVersion(), PHPFHIR_CLASSNAME_VERSION_TYPE_MAP); $imports->addVersionCoreFileImportsByName($type->getVersion(), PHPFHIR_CLASSNAME_VERSION); } else { if ($ptk === TypeKindEnum::PRIMITIVE_CONTAINER) { - $primType = $propertyType->getLocalProperties()->getProperty(PHPFHIR_VALUE_PROPERTY_NAME)->getValueFHIRType(); + $primType = $propertyType->getProperties()->getProperty(PHPFHIR_VALUE_PROPERTY_NAME)->getValueFHIRType(); $imports->addImport($primType->getFullyQualifiedNamespace(false), $primType->getClassName()); } diff --git a/src/Utilities/TypeHintUtils.php b/src/Utilities/TypeHintUtils.php index 6d1616c8..baa8af99 100644 --- a/src/Utilities/TypeHintUtils.php +++ b/src/Utilities/TypeHintUtils.php @@ -142,7 +142,7 @@ public static function typeSetterTypeHint(Version $version, Type $type, bool $nu $types = $nullable ? ['null'] : []; if ($tk === TypeKindEnum::PRIMITIVE_CONTAINER) { - $pt = $type->getLocalProperties()->getProperty('value')->getValueFHIRType(); + $pt = $type->getProperties()->getProperty('value')->getValueFHIRType(); $types = array_merge($types, $pt->getPrimitiveType()->getPHPReceiveValueTypeHints()); array_push( $types, @@ -256,7 +256,7 @@ public static function propertySetterTypeDoc(Version $version, Property $propert $hintTypes = ['null']; if ($ptk === TypeKindEnum::PRIMITIVE_CONTAINER) { - $ptp = $pt->getLocalProperties()->getProperty('value')->getValueFHIRType(); + $ptp = $pt->getProperties()->getProperty('value')->getValueFHIRType(); $hintTypes = array_merge($hintTypes, $ptp->getPrimitiveType()->getPHPReceiveValueTypeHints()); array_push( $hintTypes, diff --git a/src/Version/Definition/Decorator/AttributeElementTypeDecorator.php b/src/Version/Definition/Decorator/AttributeElementTypeDecorator.php index 3f93be67..9a250976 100644 --- a/src/Version/Definition/Decorator/AttributeElementTypeDecorator.php +++ b/src/Version/Definition/Decorator/AttributeElementTypeDecorator.php @@ -82,6 +82,6 @@ public static function decorate( } // add property to type - $type->getLocalProperties()->addProperty($property); + $type->getProperties()->addProperty($property); } } \ No newline at end of file diff --git a/src/Version/Definition/Decorator/ChoiceElementElementPropertyDecorator.php b/src/Version/Definition/Decorator/ChoiceElementElementPropertyDecorator.php index 224765b9..c7e23e74 100644 --- a/src/Version/Definition/Decorator/ChoiceElementElementPropertyDecorator.php +++ b/src/Version/Definition/Decorator/ChoiceElementElementPropertyDecorator.php @@ -118,6 +118,6 @@ public static function decorate( } } - $type->getLocalProperties()->addProperty($property); + $type->getProperties()->addProperty($property); } } \ No newline at end of file diff --git a/src/Version/Definition/Decorator/ElementElementTypeDecorator.php b/src/Version/Definition/Decorator/ElementElementTypeDecorator.php index 637e75f5..1d5eab2d 100644 --- a/src/Version/Definition/Decorator/ElementElementTypeDecorator.php +++ b/src/Version/Definition/Decorator/ElementElementTypeDecorator.php @@ -144,6 +144,6 @@ public static function decorate(Config $config, Types $types, Type $type, Simple } } - $type->getLocalProperties()->addProperty($property); + $type->getProperties()->addProperty($property); } } \ No newline at end of file diff --git a/src/Version/Definition/Properties.php b/src/Version/Definition/Properties.php index 653e4d91..47d7d82a 100644 --- a/src/Version/Definition/Properties.php +++ b/src/Version/Definition/Properties.php @@ -18,19 +18,16 @@ * limitations under the License. */ -use Countable; -use DCarbone\PHPFHIR\Config; use DCarbone\PHPFHIR\Enum\TypeKindEnum; -use DCarbone\PHPFHIR\Version; /** * Class Properties * @package DCarbone\PHPFHIR\Version\Definition\Type */ -class Properties implements Countable +class Properties { /** @var \DCarbone\PHPFHIR\Version\Definition\Property[] */ - private array $properties = []; + private array $_properties = []; /** @var \DCarbone\PHPFHIR\Version\Definition\Property[] */ private array $_sortedProperties; @@ -40,27 +37,17 @@ class Properties implements Countable private array $_localSortedProperties; /** @var bool */ - private bool $cacheBuilt = false; - - /** @var \DCarbone\PHPFHIR\Config */ - private Config $config; - - /** @var \DCarbone\PHPFHIR\Version */ - private Version $version; + private bool $_cacheBuilt = false; /** @var \DCarbone\PHPFHIR\Version\Definition\Type */ - private Type $type; + private Type $_type; /** - * @param \DCarbone\PHPFHIR\Config $config - * @param \DCarbone\PHPFHIR\Version $version * @param \DCarbone\PHPFHIR\Version\Definition\Type $type */ - public function __construct(Config $config, Version $version, Type $type) + public function __construct(Type $type) { - $this->config = $config; - $this->version = $version; - $this->type = $type; + $this->_type = $type; } /** @@ -68,7 +55,7 @@ public function __construct(Config $config, Version $version, Type $type) */ public function __debugInfo() { - return ['properties' => $this->properties]; + return ['properties' => $this->_properties]; } /** @@ -76,7 +63,7 @@ public function __debugInfo() */ public function getType(): Type { - return $this->type; + return $this->_type; } /** @@ -95,14 +82,14 @@ public function addProperty(Property &$property): Properties ) ); } - foreach ($this->properties as $current) { + foreach ($this->_properties as $current) { if ($property === $current) { return $this; } $cname = $current->getName(); $cref = $current->getRef(); if (null !== $pname && null !== $cname && $pname === $cname) { - $this->config->getLogger()->notice( + $this->_type->getConfig()->getLogger()->notice( sprintf( 'Type "%s" already has Property "%s" (name), probably some duplicate definition nonsense. Keeping original.', $this->getType()->getFHIRName(), @@ -112,7 +99,7 @@ public function addProperty(Property &$property): Properties $property = $current; return $this; } elseif (null !== $pref && null !== $cref && $cref === $pref) { - $this->config->getLogger()->notice( + $this->_type->getConfig()->getLogger()->notice( sprintf( 'Type "%s" already has Property "%s" (ref), probably some duplicate definition nonsense. Keeping original.', $this->getType()->getFHIRName(), @@ -123,8 +110,8 @@ public function addProperty(Property &$property): Properties return $this; } } - $this->properties[] = $property; - $this->cacheBuilt = false; + $this->_properties[] = $property; + $this->_cacheBuilt = false; return $this; } @@ -134,7 +121,7 @@ public function addProperty(Property &$property): Properties */ public function getProperty(string $name): ?Property { - foreach ($this->properties as $property) { + foreach ($this->_properties as $property) { if ($property->getName() === $name) { return $property; } @@ -151,6 +138,31 @@ public function hasProperty(string $name): bool return null !== $this->getProperty($name); } + /** + * @return int + */ + public function allPropertyCount(): int + { + return count($this->_properties); + } + + /** + * @return int + */ + public function localPropertyCount(): int + { + $this->_buildCaches(); + return count($this->_localProperties); + } + + /** + * @return bool + */ + public function hasLocalProperties(): bool + { + return $this->localPropertyCount() > 0; + } + /** * Returns an iterator containing all properties, including those inherited from parent types * @@ -158,7 +170,17 @@ public function hasProperty(string $name): bool */ public function getAllPropertiesIterator(): iterable { - return new \ArrayIterator($this->properties); + return new \ArrayIterator($this->_properties); + } + + /** + * @return \Generator + */ + public function getAllPropertiesGenerator(): \Generator + { + foreach ($this->_properties as $p) { + yield $p; + } } /** @@ -168,7 +190,7 @@ public function getAllPropertiesIterator(): iterable */ public function getAllSortedPropertiesIterator(): iterable { - $this->_buildLocalCaches(); + $this->_buildCaches(); return new \ArrayIterator($this->_sortedProperties); } @@ -179,7 +201,7 @@ public function getAllSortedPropertiesIterator(): iterable */ public function getIndexedLocalPropertiesIterator(): iterable { - $this->_buildLocalCaches(); + $this->_buildCaches(); return \SplFixedArray::fromArray($this->_localProperties, preserveKeys: false); } @@ -190,7 +212,7 @@ public function getIndexedLocalPropertiesIterator(): iterable */ public function getLocalPropertiesIterator(): iterable { - $this->_buildLocalCaches(); + $this->_buildCaches(); return new \ArrayIterator($this->_localProperties); } @@ -199,8 +221,8 @@ public function getLocalPropertiesIterator(): iterable */ public function getLocalPropertiesGenerator(): \Generator { - $this->_buildLocalCaches(); - foreach($this->_localProperties as $p) { + $this->_buildCaches(); + foreach ($this->_localProperties as $p) { yield $p; } } @@ -212,7 +234,7 @@ public function getLocalPropertiesGenerator(): \Generator */ public function getLocalSortedPropertiesIterator(): iterable { - $this->_buildLocalCaches(); + $this->_buildCaches(); return new \ArrayIterator($this->_localSortedProperties); } @@ -235,18 +257,10 @@ public function getLocalPropertiesOfTypeKinds(bool $includeCollections, null|Typ return new \ArrayIterator($out); } - /** - * @return int - */ - public function count(): int - { - return count($this->properties); - } - - private function _buildLocalCaches(): void + private function _buildCaches(): void { - if (!$this->cacheBuilt) { - $this->_sortedProperties = $this->properties; + if (!$this->_cacheBuilt) { + $this->_sortedProperties = $this->_properties; $this->_localProperties = []; $this->_localSortedProperties = []; usort( @@ -255,7 +269,7 @@ function (Property $a, Property $b) { return strnatcmp($a->getName(), $b->getName()); } ); - foreach ($this->properties as $property) { + foreach ($this->_properties as $property) { if (!$property->isOverloaded()) { $this->_localProperties[] = $property; } @@ -265,7 +279,7 @@ function (Property $a, Property $b) { $this->_localSortedProperties[] = $property; } } - $this->cacheBuilt = true; + $this->_cacheBuilt = true; } } } \ No newline at end of file diff --git a/src/Version/Definition/Type.php b/src/Version/Definition/Type.php index a4ee3a7b..f7fbda06 100644 --- a/src/Version/Definition/Type.php +++ b/src/Version/Definition/Type.php @@ -36,71 +36,71 @@ */ class Type { - use DocumentationTrait; - use SourceTrait; + use DocumentationTrait, + SourceTrait; /** @var \DCarbone\PHPFHIR\Config */ - private Config $config; + private Config $_config; /** @var \DCarbone\PHPFHIR\Version */ - private Version $version; + private Version $_version; /** * The raw name of the FHIR element this type was created from * @var string */ - private string $fhirName; + private string $_fhirName; /** @var \DCarbone\PHPFHIR\Enum\TypeKindEnum|null */ - private null|TypeKindEnum $kind = null; + private null|TypeKindEnum $_kind = null; /** @var string */ - private string $className; + private string $_className; /** @var \DCarbone\PHPFHIR\Version\Definition\Properties */ - private Properties $localProperties; + private Properties $_properties; /** @var null|string */ - private null|string $parentTypeName = null; + private null|string $_parentTypeName = null; /** @var null|\DCarbone\PHPFHIR\Version\Definition\Type */ - private null|Type $parentType = null; + private null|Type $_parentType = null; /** @var int */ - private int $minLength = 0; + private int $_minLength = 0; /** @var int */ - private int $maxLength = PHPFHIR_UNLIMITED; + private int $_maxLength = PHPFHIR_UNLIMITED; /** @var null|string */ - private null|string $pattern = null; + private null|string $_pattern = null; /** @var null|\DCarbone\PHPFHIR\Version\Definition\Type */ - private null|Type $componentOfType = null; + private null|Type $_componentOfType = null; /** @var \DCarbone\PHPFHIR\Version\Definition\Enumeration */ - private Enumeration $enumeration; + private Enumeration $_enumeration; /** @var array */ - private array $unionOf = []; + private array $_unionOf = []; /** @var \DCarbone\PHPFHIR\Enum\PrimitiveTypeEnum */ - private PrimitiveTypeEnum $primitiveType; + private PrimitiveTypeEnum $_primitiveType; /** @var null|string */ - private null|string $restrictionBaseFHIRName = null; + private null|string $_restrictionBaseFHIRName = null; /** @var null|\DCarbone\PHPFHIR\Version\Definition\Type */ - private null|Type $restrictionBaseFHIRType = null; + private null|Type $_restrictionBaseFHIRType = null; /** @var bool */ // TODO: what the hell is this...? - private bool $mixed = false; + private bool $_mixed = false; /** @var bool */ - private bool $containedType = false; + private bool $_containedType = false; /** @var bool */ - private bool $valueContainer = false; + private bool $_valueContainer = false; /** @var bool */ - private bool $commentContainer = false; + private bool $_commentContainer = false; /** @var \DCarbone\PHPFHIR\Builder\Imports */ - private Imports $imports; + private Imports $_imports; /** * Type constructor. @@ -110,24 +110,22 @@ class Type * @param \SimpleXMLElement|null $sourceSXE * @param string $sourceFilename */ - public function __construct( - Config $config, - Version $version, - string $fhirName, - null|SimpleXMLElement $sourceSXE = null, - string $sourceFilename = '' - ) + public function __construct(Config $config, + Version $version, + string $fhirName, + null|SimpleXMLElement $sourceSXE = null, + string $sourceFilename = '') { if ('' === ($fhirName = trim($fhirName))) { throw new DomainException('$fhirName must be defined'); } - $this->config = $config; - $this->version = $version; - $this->fhirName = $fhirName; + $this->_config = $config; + $this->_version = $version; + $this->_fhirName = $fhirName; $this->sourceSXE = $sourceSXE; $this->sourceFilename = $sourceFilename; - $this->localProperties = new Properties($config, $version, $this); - $this->enumeration = new Enumeration(); + $this->_properties = new Properties($this); + $this->_enumeration = new Enumeration(); } /** @@ -145,7 +143,7 @@ public function __debugInfo() */ public function getConfig(): Config { - return $this->config; + return $this->_config; } /** @@ -153,7 +151,7 @@ public function getConfig(): Config */ public function getVersion(): Version { - return $this->version; + return $this->_version; } /** @@ -161,7 +159,7 @@ public function getVersion(): Version */ public function getFHIRName(): string { - return $this->fhirName; + return $this->_fhirName; } /** @@ -170,14 +168,14 @@ public function getFHIRName(): string public function getImports(): Imports { // TODO: implement "extraction done" mechanic - if (!isset($this->imports)) { - $this->imports = new Imports( - $this->config, + if (!isset($this->_imports)) { + $this->_imports = new Imports( + $this->_config, $this->getFullyQualifiedNamespace(false), $this->getClassName(), ); } - return $this->imports; + return $this->_imports; } /** @@ -219,7 +217,7 @@ public function getClassNameConst(bool $withClass): string */ public function getKind(): null|TypeKindEnum { - return $this->kind; + return $this->_kind; } /** @@ -228,17 +226,17 @@ public function getKind(): null|TypeKindEnum */ public function setKind(TypeKindEnum $kind): Type { - if (isset($this->kind) && $this->kind !== $kind) { + if (isset($this->_kind) && $this->_kind !== $kind) { throw new LogicException( sprintf( 'Cannot overwrite Type % s Kind from %s to %s', $this->getFHIRName(), - $this->kind->value, + $this->_kind->value, $kind->value ) ); } - $this->kind = $kind; + $this->_kind = $kind; return $this; } @@ -248,17 +246,17 @@ public function setKind(TypeKindEnum $kind): Type */ public function setPrimitiveType(PrimitiveTypeEnum $primitiveType): Type { - if (isset($this->primitiveType) && $this->primitiveType === $primitiveType) { + if (isset($this->_primitiveType) && $this->_primitiveType === $primitiveType) { throw new LogicException( sprintf( 'Cannot overwrite Type "%s" PrimitiveType from "%s" to "%s"', $this->getFHIRName(), - $this->primitiveType->value, + $this->_primitiveType->value, $primitiveType->value ) ); } - $this->primitiveType = $primitiveType; + $this->_primitiveType = $primitiveType; return $this; } @@ -286,10 +284,10 @@ public function getTypeNamespace(): string */ public function getClassName(): string { - if (!isset($this->className)) { - $this->className = NameUtils::getTypeClassName($this->getFHIRName()); + if (!isset($this->_className)) { + $this->_className = NameUtils::getTypeClassName($this->getFHIRName()); } - return $this->className; + return $this->_className; } /** @@ -317,7 +315,9 @@ public function getFullyQualifiedTestNamespace(TestTypeEnum $testType, bool $lea */ public function getFullyQualifiedClassName(bool $leadingSlash): string { - return $this->getVersion()->getFullyQualifiedName($leadingSlash, $this->getTypeNamespace(), $this->getClassName()); + return $this + ->getVersion() + ->getFullyQualifiedName($leadingSlash, $this->getTypeNamespace(), $this->getClassName()); } /** @@ -341,9 +341,9 @@ public function getFullyQualifiedTestClassName($testType, bool $leadingSlash): s /** * @return \DCarbone\PHPFHIR\Version\Definition\Properties */ - public function getLocalProperties(): Properties + public function getProperties(): Properties { - return $this->localProperties; + return $this->_properties; } /** @@ -353,7 +353,7 @@ public function getLocalProperties(): Properties */ public function hasLocalProperties(): bool { - return count($this->localProperties) > 0; + return $this->_properties->hasLocalProperties(); } /** @@ -361,7 +361,7 @@ public function hasLocalProperties(): bool */ public function hasLocalPropertiesWithValidations(): bool { - foreach ($this->getlocalProperties()->getAllSortedPropertiesIterator() as $property) { + foreach ($this->getProperties()->getAllSortedPropertiesIterator() as $property) { if ([] !== $property->buildValidationMap()) { return true; } @@ -375,11 +375,11 @@ public function hasLocalPropertiesWithValidations(): bool public function getAllPropertiesIndexedIterator(): iterable { $properties = []; - foreach ($this->getLocalProperties()->getLocalPropertiesIterator() as $property) { + foreach ($this->getProperties()->getAllPropertiesGenerator() as $property) { $properties[$property->getName()] = $property; } foreach ($this->getParentTypes() as $parentType) { - foreach ($parentType->getAllPropertiesIndexedIterator() as $property) { + foreach ($parentType->getProperties()->getAllPropertiesGenerator() as $property) { if (!isset($properties[$property->getName()])) { $properties[$property->getName()] = $property; } @@ -428,7 +428,7 @@ public function getRootType(): Type */ public function getParentType(): null|Type { - return $this->parentType; + return $this->_parentType; } /** @@ -455,7 +455,7 @@ public function hasParentWithLocalProperties(): bool */ public function setParentType(Type $type): Type { - $this->parentType = $type; + $this->_parentType = $type; $this->setParentTypeName($type->getFHIRName()); return $this; } @@ -465,7 +465,7 @@ public function setParentType(Type $type): Type */ public function getParentTypeName(): null|string { - return $this->parentTypeName; + return $this->_parentTypeName; } /** @@ -474,7 +474,7 @@ public function getParentTypeName(): null|string */ public function setParentTypeName(null|string $parentTypeName): Type { - $this->parentTypeName = $parentTypeName; + $this->_parentTypeName = $parentTypeName; return $this; } @@ -525,7 +525,7 @@ public function isResourceType(): bool */ public function getMinLength(): int { - return $this->minLength; + return $this->_minLength; } /** @@ -534,7 +534,7 @@ public function getMinLength(): int */ public function setMinLength(int $minLength): Type { - $this->minLength = $minLength; + $this->_minLength = $minLength; return $this; } @@ -543,7 +543,7 @@ public function setMinLength(int $minLength): Type */ public function getMaxLength(): int { - return $this->maxLength; + return $this->_maxLength; } /** @@ -552,7 +552,7 @@ public function getMaxLength(): int */ public function setMaxLength(int $maxLength): Type { - $this->maxLength = $maxLength; + $this->_maxLength = $maxLength; return $this; } @@ -561,7 +561,7 @@ public function setMaxLength(int $maxLength): Type */ public function getPattern(): null|string { - return $this->pattern; + return $this->_pattern; } /** @@ -570,7 +570,7 @@ public function getPattern(): null|string */ public function setPattern(null|string $pattern): Type { - $this->pattern = $pattern; + $this->_pattern = $pattern; return $this; } @@ -579,7 +579,7 @@ public function setPattern(null|string $pattern): Type */ public function getComponentOfType(): null|Type { - return $this->componentOfType; + return $this->_componentOfType; } /** @@ -588,7 +588,7 @@ public function getComponentOfType(): null|Type */ public function setComponentOfType(Type $type): Type { - $this->componentOfType = $type; + $this->_componentOfType = $type; return $this; } @@ -597,7 +597,7 @@ public function setComponentOfType(Type $type): Type */ public function getEnumeration(): Enumeration { - return $this->enumeration; + return $this->_enumeration; } /** @@ -606,7 +606,7 @@ public function getEnumeration(): Enumeration */ public function addEnumerationValue(EnumerationValue $enumValue): Type { - $this->enumeration->addValue($enumValue); + $this->_enumeration->addValue($enumValue); return $this; } @@ -623,7 +623,7 @@ public function isEnumerated(): bool */ public function getPrimitiveType(): PrimitiveTypeEnum { - return $this->primitiveType; + return $this->_primitiveType; } /** @@ -631,7 +631,7 @@ public function getPrimitiveType(): PrimitiveTypeEnum */ public function hasPrimitiveType(): bool { - return isset($this->primitiveType); + return isset($this->_primitiveType); } /** @@ -639,7 +639,7 @@ public function hasPrimitiveType(): bool */ public function getUnionOf(): array { - return $this->unionOf; + return $this->_unionOf; } /** @@ -648,7 +648,7 @@ public function getUnionOf(): array */ public function setUnionOf(array $unionOf): Type { - $this->unionOf = $unionOf; + $this->_unionOf = $unionOf; return $this; } @@ -657,7 +657,7 @@ public function setUnionOf(array $unionOf): Type */ public function getRestrictionBaseFHIRName(): null|string { - return $this->restrictionBaseFHIRName; + return $this->_restrictionBaseFHIRName; } /** @@ -666,7 +666,7 @@ public function getRestrictionBaseFHIRName(): null|string */ public function setRestrictionBaseFHIRName(string $restrictionBaseFHIRName): Type { - $this->restrictionBaseFHIRName = $restrictionBaseFHIRName; + $this->_restrictionBaseFHIRName = $restrictionBaseFHIRName; return $this; } @@ -675,7 +675,7 @@ public function setRestrictionBaseFHIRName(string $restrictionBaseFHIRName): Typ */ public function getRestrictionBaseFHIRType(): null|Type { - return $this->restrictionBaseFHIRType; + return $this->_restrictionBaseFHIRType; } /** @@ -684,7 +684,7 @@ public function getRestrictionBaseFHIRType(): null|Type */ public function setRestrictionBaseFHIRType(Type $type): Type { - $this->restrictionBaseFHIRType = $type; + $this->_restrictionBaseFHIRType = $type; return $this; } @@ -693,7 +693,7 @@ public function setRestrictionBaseFHIRType(Type $type): Type */ public function isMixed(): bool { - return $this->mixed; + return $this->_mixed; } /** @@ -702,7 +702,7 @@ public function isMixed(): bool */ public function setMixed(bool $mixed): Type { - $this->mixed = $mixed; + $this->_mixed = $mixed; return $this; } @@ -711,7 +711,7 @@ public function setMixed(bool $mixed): Type */ public function isContainedType(): bool { - return $this->containedType; + return $this->_containedType; } /** @@ -720,7 +720,7 @@ public function isContainedType(): bool */ public function setContainedType(bool $containedType): Type { - $this->containedType = $containedType; + $this->_containedType = $containedType; return $this; } @@ -729,7 +729,7 @@ public function setContainedType(bool $containedType): Type */ public function isValueContainer(): bool { - return $this->valueContainer; + return $this->_valueContainer; } /** @@ -738,7 +738,7 @@ public function isValueContainer(): bool */ public function setValueContainer(bool $valueContainer): Type { - $this->valueContainer = $valueContainer; + $this->_valueContainer = $valueContainer; return $this; } @@ -766,8 +766,8 @@ public function getDirectlyImplementedInterfaces(): array { $interfaces = []; $parentType = $this->getParentType(); - $coreFiles = $this->version->getConfig()->getCoreFiles(); - $versionCoreFiles = $this->version->getCoreFiles(); + $coreFiles = $this->_version->getConfig()->getCoreFiles(); + $versionCoreFiles = $this->_version->getCoreFiles(); if (null === $parentType) { if ($this->isCommentContainer()) { @@ -804,7 +804,7 @@ public function getDirectlyUsedTraits(): array { $traits = []; $parentType = $this->getParentType(); - $coreFiles = $this->version->getConfig()->getCoreFiles(); + $coreFiles = $this->_version->getConfig()->getCoreFiles(); if (null === $parentType) { // if this type has no parent(s), try to add all traits @@ -850,7 +850,7 @@ public function hasCommentContainerParent(): bool */ public function setCommentContainer(bool $commentContainer): Type { - $this->commentContainer = $commentContainer; + $this->_commentContainer = $commentContainer; return $this; } @@ -859,7 +859,7 @@ public function setCommentContainer(bool $commentContainer): Type */ public function isCommentContainer(): bool { - return $this->commentContainer; + return $this->_commentContainer; } /** diff --git a/src/Version/Definition/TypeDecorationValidator.php b/src/Version/Definition/TypeDecorationValidator.php index b9fef161..de285b78 100644 --- a/src/Version/Definition/TypeDecorationValidator.php +++ b/src/Version/Definition/TypeDecorationValidator.php @@ -81,7 +81,7 @@ public static function validateDecoration(Config $config, Version $version, Type } if ($typeKind === TypeKindenum::PRIMITIVE_CONTAINER) { - $valueProperty = $type->getLocalProperties()->getProperty('value'); + $valueProperty = $type->getProperties()->getProperty('value'); if (null === $valueProperty) { throw ExceptionUtils::createPrimitiveValuePropertyNotFound($type); } @@ -91,7 +91,7 @@ public static function validateDecoration(Config $config, Version $version, Type throw ExceptionUtils::createContainedTypeFlagMismatchException($types->isContainedType($type), $type); } - foreach ($type->getLocalProperties()->getAllPropertiesIterator() as $property) { + foreach ($type->getProperties()->getAllPropertiesIterator() as $property) { $name = $property->getName(); if (null === $name || '' === $name) { throw ExceptionUtils::createPropertyMissingNameException($type, $property); diff --git a/src/Version/Definition/TypeDecorator.php b/src/Version/Definition/TypeDecorator.php index 01a9319a..27f46912 100644 --- a/src/Version/Definition/TypeDecorator.php +++ b/src/Version/Definition/TypeDecorator.php @@ -385,10 +385,10 @@ public static function setValueContainerFlag(Config $config, Types $types): void continue; } - $properties = $type->getLocalProperties(); + $properties = $type->getProperties(); // only target types with a single field on them with the name "value" - if (1 !== count($properties) || !$properties->hasProperty(PHPFHIR_VALUE_PROPERTY_NAME)) { + if (1 !== $properties->localPropertyCount() || !$properties->hasProperty(PHPFHIR_VALUE_PROPERTY_NAME)) { continue; } @@ -443,8 +443,8 @@ public static function parseUnionMemberTypes(Config $config, Types $types): void $utype->getFHIRName() ) ); - foreach ($utype->getLocalProperties()->getAllPropertiesIterator() as $property) { - $type->getLocalProperties()->addProperty(clone $property); + foreach ($utype->getProperties()->getAllPropertiesIterator() as $property) { + $type->getProperties()->addProperty(clone $property); } } else { $log->info( @@ -462,6 +462,10 @@ public static function parseUnionMemberTypes(Config $config, Types $types): void } } + /** + * @param \DCarbone\PHPFHIR\Config $config + * @param \DCarbone\PHPFHIR\Version\Definition\Types $types + */ public static function buildTypeImports(Config $config, Types $types): void { foreach ($types->getGenerator() as $type) { diff --git a/src/Version/Definition/TypePropertyDecorator.php b/src/Version/Definition/TypePropertyDecorator.php index 34a793d4..059d150d 100644 --- a/src/Version/Definition/TypePropertyDecorator.php +++ b/src/Version/Definition/TypePropertyDecorator.php @@ -118,7 +118,7 @@ public static function findPropertyType(Config $config, Types $types, Type $type public static function findPropertyTypes(Config $config, Types $types): void { foreach ($types->getGenerator() as $type) { - foreach ($type->getLocalProperties()->getAllPropertiesIterator() as $property) { + foreach ($type->getProperties()->getAllPropertiesIterator() as $property) { self::findPropertyType($config, $types, $type, $property); } } @@ -137,9 +137,9 @@ public static function findOverloadedProperties(Config $config, Types $types): v } $parent = $type->getParentType(); while (null !== $parent) { - foreach ($type->getLocalProperties()->getAllPropertiesIterator() as $property) { + foreach ($type->getProperties()->getAllPropertiesIterator() as $property) { $propertyName = $property->getName(); - foreach ($parent->getLocalProperties()->getAllPropertiesIterator() as $parentProperty) { + foreach ($parent->getProperties()->getAllPropertiesIterator() as $parentProperty) { if ($propertyName === $parentProperty->getName()) { $logger->debug( sprintf( @@ -167,7 +167,7 @@ public static function setMissingPropertyNames(Config $config, Types $types): vo { $log = $config->getLogger(); foreach ($types->getGenerator() as $type) { - foreach ($type->getLocalProperties()->getAllPropertiesIterator() as $property) { + foreach ($type->getProperties()->getAllPropertiesIterator() as $property) { $propName = $property->getName(); if ('' === $propName || null === $propName) { $ref = $property->getRef(); diff --git a/src/Version/Definition/Types.php b/src/Version/Definition/Types.php index 5c95733e..c424aed8 100644 --- a/src/Version/Definition/Types.php +++ b/src/Version/Definition/Types.php @@ -239,7 +239,7 @@ public function isContainedType(Type $type): bool if (null === $container) { return false; } - foreach ($container->getLocalProperties()->getAllPropertiesIterator() as $property) { + foreach ($container->getProperties()->getAllPropertiesIterator() as $property) { if (($ptype = $property->getValueFHIRType()) && $ptype->getFHIRName() === $type->getFHIRName()) { return true; } diff --git a/template/versions/core/class_version_type_map.php b/template/versions/core/class_version_type_map.php index 3bff22fb..cc307ca1 100644 --- a/template/versions/core/class_version_type_map.php +++ b/template/versions/core/class_version_type_map.php @@ -48,7 +48,7 @@ /** @var \DCarbone\PHPFHIR\Version\Definition\Type[] $innerTypes */ $innerTypes = []; -foreach ($containerType->getLocalProperties()->getAllPropertiesIterator() as $property) { +foreach ($containerType->getProperties()->getAllPropertiesIterator() as $property) { if ($ptype = $property->getValueFHIRType()) { $innerTypes[$ptype->getFHIRName()] = $ptype; } diff --git a/template/versions/types/class_default.php b/template/versions/types/class_default.php index 53eb9012..6d704c43 100644 --- a/template/versions/types/class_default.php +++ b/template/versions/types/class_default.php @@ -45,7 +45,7 @@ // -- property field name constants if ($type->hasLocalProperties()) : echo "\n"; - foreach ($type->getLocalProperties()->getLocalPropertiesGenerator() as $property) : + foreach ($type->getProperties()->getLocalPropertiesGenerator() as $property) : if ($property->getMemberOf()->hasPrimitiveParent()) { continue; } @@ -54,7 +54,7 @@ public const getFieldConstantName(); ?> = 'getName(); ?>'; getKind() === TypeKindEnum::PRIMITIVE_CONTAINER || $propertyType->isValueContainer())) : - ?> public const getFieldConstantName(); ?>_EXT = 'getExtName(); ?>'; + ?> public const getFieldConstantName(); ?>_EXT = 'getExtName(); ?>'; getLocalProperties()->getLocalPropertiesGenerator() as $property) : ?> + foreach ($type->getProperties()->getLocalPropertiesGenerator() as $property) : ?> /** * @var @@ -79,7 +79,7 @@ getLocalProperties()->getLocalPropertiesGenerator() as $property) : + foreach ($type->getProperties()->getLocalPropertiesGenerator() as $property) : $validationMap = $property->buildValidationMap(); if ([] !== $validationMap) : ?> diff --git a/template/versions/types/methods/constructor.php b/template/versions/types/methods/constructor.php index 6404f2e8..c042433d 100644 --- a/template/versions/types/methods/constructor.php +++ b/template/versions/types/methods/constructor.php @@ -28,10 +28,10 @@ $parentType = $type->getParentType(); -$localProperties = $type->getLocalProperties()->getLocalPropertiesIterator(); +$localProperties = $type->getProperties()->getLocalPropertiesIterator(); // used in a few places below. -$valueProperty = $type->getLocalProperties()->getProperty(PHPFHIR_VALUE_PROPERTY_NAME); +$valueProperty = $type->getProperties()->getProperty(PHPFHIR_VALUE_PROPERTY_NAME); ob_start(); diff --git a/template/versions/types/properties/methods/default.php b/template/versions/types/properties/methods/default.php index e41b0ebf..c4a5a609 100644 --- a/template/versions/types/properties/methods/default.php +++ b/template/versions/types/properties/methods/default.php @@ -35,7 +35,7 @@ $isPrimitiveType = $type->getKind()->isOneOf(TypeKindEnum::PRIMITIVE, TypeKindEnum::LIST); ob_start(); -foreach ($type->getLocalProperties()->getIndexedLocalPropertiesIterator() as $i => $property) : +foreach ($type->getProperties()->getIndexedLocalPropertiesIterator() as $i => $property) : if ($property->isOverloaded()) { continue; } diff --git a/template/versions/types/serialization/json.php b/template/versions/types/serialization/json.php index 9c45b2f8..0c6a0cd9 100644 --- a/template/versions/types/serialization/json.php +++ b/template/versions/types/serialization/json.php @@ -21,7 +21,7 @@ /** @var \DCarbone\PHPFHIR\Version $version */ /** @var \DCarbone\PHPFHIR\Version\Definition\Type $type */ -$localProperties = $type->getLocalProperties()->getLocalPropertiesIterator(); +$localProperties = $type->getProperties()->getLocalPropertiesIterator(); $typeKind = $type->getKind(); ob_start(); diff --git a/template/versions/types/serialization/json/default.php b/template/versions/types/serialization/json/default.php index f1556280..195cbe57 100644 --- a/template/versions/types/serialization/json/default.php +++ b/template/versions/types/serialization/json/default.php @@ -38,7 +38,7 @@ public function jsonSerialize(): mixed $out->{::JSON_FIELD_FHIR_COMMENTS} = $vs; } getLocalProperties()->getLocalPropertiesGenerator() as $property) : +foreach ($type->getProperties()->getLocalPropertiesGenerator() as $property) : $propConst = $property->getFieldConstantName(); $propConstExt = $property->getFieldConstantExtensionName(); $getter = $property->getGetterName(); diff --git a/template/versions/types/serialization/json/resource_container.php b/template/versions/types/serialization/json/resource_container.php index b425b696..fb29edf8 100644 --- a/template/versions/types/serialization/json/resource_container.php +++ b/template/versions/types/serialization/json/resource_container.php @@ -24,7 +24,7 @@ * @return null|object */ public function jsonSerialize(): mixed - {getLocalProperties()->getLocalPropertiesGenerator() as $property) : ?> + {getProperties()->getLocalPropertiesGenerator() as $property) : ?> if (null !== ($v = $this->getgetName()); ?>())) { return $v; diff --git a/template/versions/types/serialization/xml/serialize/body.php b/template/versions/types/serialization/xml/serialize/body.php index fbeb2ecf..222d098a 100644 --- a/template/versions/types/serialization/xml/serialize/body.php +++ b/template/versions/types/serialization/xml/serialize/body.php @@ -27,11 +27,11 @@ // this is only used in primitive types. they have no other fields, and I am just going to assume you want it // as an attribute if marshalled directly. -foreach ($type->getLocalProperties()->getLocalPropertiesOfTypeKinds(includeCollections: false, kinds: null) as $property) : ?> +foreach ($type->getProperties()->getLocalPropertiesOfTypeKinds(includeCollections: false, kinds: null) as $property) : ?> $xw->writeAttribute(self::FIELD_VALUE, $this->getFormattedValue()); getLocalProperties()->getLocalPropertiesIterator() as $property) : +foreach ($type->getProperties()->getLocalPropertiesIterator() as $property) : $pt = $property->getValueFHIRType(); if (null === $pt) { continue; @@ -71,7 +71,7 @@ getLocalProperties()->getLocalPropertiesGenerator() as $property) : +foreach ($type->getProperties()->getLocalPropertiesGenerator() as $property) : $pt = $property->getValueFHIRType(); // if this property has a "type"... diff --git a/template/versions/types/serialization/xml/serialize/resource_container.php b/template/versions/types/serialization/xml/serialize/resource_container.php index 626e868f..9c902e57 100644 --- a/template/versions/types/serialization/xml/serialize/resource_container.php +++ b/template/versions/types/serialization/xml/serialize/resource_container.php @@ -50,7 +50,7 @@ public function xmlSerialize(null|())->getConfig()->getSerializeConfig(); } -getLocalProperties()->getLocalPropertiesGenerator() as $property) : ?> +getProperties()->getLocalPropertiesGenerator() as $property) : ?> if (null !== ($v = $this->getGetterName(); ?>())) { return $v->xmlSerialize($xw, $config); } diff --git a/template/versions/types/serialization/xml/unserialize/body.php b/template/versions/types/serialization/xml/unserialize/body.php index 5ed4752e..53ca8433 100644 --- a/template/versions/types/serialization/xml/unserialize/body.php +++ b/template/versions/types/serialization/xml/unserialize/body.php @@ -29,10 +29,9 @@ $propType = $property->getValueFHIRType(); $setter = $property->getSetterName(); - if ($i > 0) : ?> else 0) : ?> else getKind(); - $propTypeClassname = $property->getMemberOf()->getImports()->getImportByType($propType); if ($propTypeKind->isContainer($version)) : ?> if (self:: === $childName) { @@ -41,7 +40,9 @@ $type->($typeClassName::xmlUnserialize($nn, null, $config)); } }if (self:: === $childName) { + else : + $propTypeClassname = $property->getMemberOf()->getImports()->getImportByType($propType); + ?>if (self:: === $childName) { $type->(::xmlUnserialize($n, null, $config)hasPrimitiveParent() || $propType->getKind()->isOneOf(TypeKindEnum::PRIMITIVE, TypeKindEnum::LIST, TypeKindEnum::PRIMITIVE_CONTAINER)) : ?>, ::ELEMENT); }getKind(); - $propTypeClassname = $property->getMemberOf()->getImports()->getImportByType($propType); if ($propType->hasPrimitiveParent() || $propType->getKind()->isOneOf(TypeKindEnum::PRIMITIVE, TypeKindEnum::LIST, TypeKindEnum::PRIMITIVE_CONTAINER)) : ?> if (isset($attributes[self::])) { diff --git a/template/versions/types/validation/methods.php b/template/versions/types/validation/methods.php index ca012f17..3ae535fc 100644 --- a/template/versions/types/validation/methods.php +++ b/template/versions/types/validation/methods.php @@ -54,7 +54,7 @@ public function _getValidationErrors(): array $errs = []; $validationRules = $this->_getValidationRules(); -getLocalProperties()->getLocalPropertiesIterator() as $property) : +getProperties()->getLocalPropertiesIterator() as $property) : $validations = $property->buildValidationMap(); if ([] === $validations) { continue; @@ -110,7 +110,7 @@ public function _getValidationErrors(): array if (null !== $type->getParentType()) : $ptype = $type; while (null !== $ptype) : - foreach($ptype->getLocalProperties()->getLocalPropertiesIterator() as $property) : ?> + foreach($ptype->getProperties()->getLocalPropertiesIterator() as $property) : ?> if (isset($validationRules[self::getFieldConstantName(); ?>])) { $v = $this->getGetterName(); ?>(); foreach($validationRules[self::getFieldConstantName(); ?>] as $rule => $constraint) {