From 0d98ebd36fd0ca4a74b947265c04e33ce32d1624 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Sun, 5 Jan 2025 12:29:02 -0600 Subject: [PATCH] refactoring import system to suck a little less --- files/constants.php | 2 +- .../TypeImport.php => Builder/Import.php} | 54 ++-- src/Builder/Imports.php | 193 +++++++++++++ src/Config.php | 1 + src/CoreFile.php | 21 +- src/CoreFiles.php | 5 +- src/Utilities/ExceptionUtils.php | 4 - src/Utilities/ImportUtils.php | 123 ++++++++ src/Version.php | 1 + src/Version/Definition/Type.php | 21 +- src/Version/Definition/TypeImports.php | 267 ------------------ src/Version/VersionImports.php | 49 ++++ template/core/class_autoloader.php | 4 - template/core/class_factory.php | 10 + template/core/class_version_config.php | 33 ++- template/core/client/class_client.php | 69 +---- .../core/client/exception_client_error.php | 2 +- template/core/interface_type.php | 14 +- template/core/interface_version_config.php | 11 +- template/core/validation/class_validator.php | 14 +- template/versions/core/class_autoloader.php | 2 +- template/versions/core/class_version.php | 32 ++- .../core/class_version_api_client.php | 38 ++- template/versions/types/class_default.php | 2 +- template/versions/types/header.php | 18 +- template/versions/types/serialization/xml.php | 2 +- .../types/tests/integration/class.php | 2 +- .../versions/types/tests/validation/class.php | 2 +- 28 files changed, 557 insertions(+), 439 deletions(-) rename src/{Version/Definition/TypeImport.php => Builder/Import.php} (65%) create mode 100644 src/Builder/Imports.php create mode 100644 src/Utilities/ImportUtils.php delete mode 100644 src/Version/Definition/TypeImports.php create mode 100644 src/Version/VersionImports.php diff --git a/files/constants.php b/files/constants.php index f2ea0a42..2e5416db 100644 --- a/files/constants.php +++ b/files/constants.php @@ -111,7 +111,7 @@ // Core exceptions const PHPFHIR_EXCEPTION_CLIENT_ABSTRACT_CLIENT = 'AbstractClientException'; -const PHPFHIR_EXCEPTION_CLIENT_NETWORK_ERROR = 'ClientErrorException'; +const PHPFHIR_EXCEPTION_CLIENT_ERROR = 'ClientErrorException'; const PHPFHIR_EXCEPTION_CLIENT_UNEXPECTED_RESPONSE_CODE = 'UnexpectedResponseCodeException'; // Core client entities diff --git a/src/Version/Definition/TypeImport.php b/src/Builder/Import.php similarity index 65% rename from src/Version/Definition/TypeImport.php rename to src/Builder/Import.php index 4051a373..fe0332ef 100644 --- a/src/Version/Definition/TypeImport.php +++ b/src/Builder/Import.php @@ -1,6 +1,6 @@ classname = $classname; - $this->namespace = $namespace; - $this->fqcn = ('' === $namespace ? $classname : "{$namespace}\\{$classname}"); - $this->aliased = $aliased; - $this->aliasName = $aliasName; - $this->requiresImport = $requiresImport; + $this->_classname = $classname; + $this->_namespace = trim($namespace, PHPFHIR_NAMESPACE_SEPARATOR); + $this->_fqn = ('' === $this->_namespace ? $classname : "{$this->_namespace}\\{$classname}"); + $this->_aliasName = $aliasName; + $this->_requiresImport = $requiresImport; } /** @@ -60,7 +52,7 @@ public function __construct(string $classname, string $namespace, bool $aliased, */ public function getClassname(): string { - return $this->classname; + return $this->_classname; } /** @@ -68,7 +60,7 @@ public function getClassname(): string */ public function getNamespace(): string { - return $this->namespace; + return $this->_namespace; } /** @@ -76,7 +68,7 @@ public function getNamespace(): string */ public function isAliased(): bool { - return $this->aliased; + return isset($this->_aliasName) && '' !== $this->_aliasName; } /** @@ -84,7 +76,7 @@ public function isAliased(): bool */ public function getAliasName(): string { - return $this->aliasName; + return $this->_aliasName; } /** @@ -104,24 +96,24 @@ public function getImportedName(): string */ public function getFullyQualifiedNamespace(bool $leadingSlash): string { - return $leadingSlash ? "\\{$this->namespace}" : $this->namespace; + return $leadingSlash ? "\\{$this->_namespace}" : $this->_namespace; } /** * @param bool $leadingSlash * @return string */ - public function getFullyQualifiedClassname(bool $leadingSlash): string + public function getFullyQualifiedName(bool $leadingSlash): string { - return $leadingSlash ? "\\{$this->fqcn}" : $this->fqcn; + return $leadingSlash ? "\\{$this->_fqn}" : $this->_fqn; } /** * @return bool */ - public function isRequiresImport(): bool + public function requiresImport(): bool { - return $this->requiresImport; + return $this->_requiresImport; } /** @@ -129,7 +121,7 @@ public function isRequiresImport(): bool */ public function getUseStatement(): string { - $use = "use {$this->getFullyQualifiedClassname(false)}"; + $use = "use {$this->getFullyQualifiedName(false)}"; if ($this->isAliased()) { $use .= " as {$this->getAliasName()}"; } diff --git a/src/Builder/Imports.php b/src/Builder/Imports.php new file mode 100644 index 00000000..f481ca3b --- /dev/null +++ b/src/Builder/Imports.php @@ -0,0 +1,193 @@ +_config = $config; + $this->_localNamespace = trim($localNamespace, PHPFHIR_NAMESPACE_SEPARATOR); + $this->_localName = $localName; + } + + /** + * @param string $namespace Namespace of referenced entity + * @param string $name Name of referenced entity + * @return \DCarbone\PHPFHIR\Builder\Imports + */ + public function addImport(string $namespace, string $name): self + { + // ensure clean namespace value + $namespace = trim($namespace, PHPFHIR_NAMESPACE_SEPARATOR); + + // do not need to import sibling entities. + $requiresImport = ($namespace !== $this->_localNamespace); + + if (isset($this->_imports[$name])) { + // if we have already seen this type, move on. + if ($this->_imports[$name]->getNamespace() === $namespace) { + return $this; + } + // if there is a conflicting imported type here... + $aliasName = $this->_findNextAliasName($name); + $this->_imports[$aliasName] = new Import($name, $namespace, $aliasName, $requiresImport); + } else if ($name === $this->_localName && $namespace != $this->_localNamespace) { + // if the referenced type has the same name but exists in a different namespace, alias it. + $aliasName = $this->_findNextAliasName($name); + $this->_imports[$aliasName] = new Import($name, $namespace, $aliasName, $requiresImport); + } else { + // otherwise, go ahead and add to map. + $this->_imports[$name] = new Import($name, $namespace, '', $requiresImport); + } + + if ($requiresImport) { + $this->_requiredImportCount++; + } + + uasort( + $this->_imports, + function (Import $a, Import $b) { + return strnatcasecmp($a->getFullyQualifiedName(false), $b->getFullyQualifiedName(false)); + } + ); + + return $this; + } + + public function addCoreFileImports(string ...$entityNames): self + { + foreach ($entityNames as $en) { + $coreFile = $this->_config->getCoreFiles()->getCoreFileByEntityName($en); + $this->addImport($coreFile->getFullyQualifiedNamespace(false), $coreFile->getEntityName()); + } + return $this; + } + + /** + * @return \DCarbone\PHPFHIR\Builder\Import[] + */ + public function getIterator(): iterable + { + return new \ArrayIterator($this->_imports); + } + + /** + * @return \Generator<\DCarbone\PHPFHIR\Builder\Import> + */ + public function getGenerator(): \Generator + { + foreach ($this->_imports as $import) { + yield $import; + } + } + + /** + * @return int + */ + public function requiredImportCount(): int + { + return $this->_requiredImportCount; + } + + /** + * @param \DCarbone\PHPFHIR\Version\Definition\Type $type + * @return \DCarbone\PHPFHIR\Builder\Import|null + */ + public function getImportByType(Type $type): ?Import + { + $fqn = $type->getFullyQualifiedClassName(false); + foreach ($this->_imports as $import) { + if ($import->getFullyQualifiedName(false) === $fqn) { + return $import; + } + } + return null; + } + + /** + * @param string $classname + * @param string $namespace + * @return \DCarbone\PHPFHIR\Builder\Import|null + */ + public function getImportByClassAndNamespace(string $classname, string $namespace): null|Import + { + foreach ($this->_imports as $import) { + if ($import->getNamespace() === $namespace && $import->getClassname() === $classname) { + return $import; + } + } + return null; + } + + /** + * @param string $aliasName + * @return \DCarbone\PHPFHIR\Builder\Import|null + */ + public function getImportByAlias(string $aliasName): ?Import + { + return $this->_imports[$aliasName] ?? null; + } + + /** + * @return int + */ + public function count(): int + { + return count($this->_imports); + } + + /** + * TODO: come up with better alias scheme... + * + * @param string $classname + * @return string + */ + private function _findNextAliasName(string $classname): string + { + $i = 1; + $aliasName = "{$classname}{$i}"; + while (null !== $this->getImportByAlias($aliasName)) { + $aliasName = "{$classname}{++$i}"; + } + return $aliasName; + } +} \ No newline at end of file diff --git a/src/Config.php b/src/Config.php index 8b471982..0eeb8165 100644 --- a/src/Config.php +++ b/src/Config.php @@ -121,6 +121,7 @@ public function __construct(array $params = [], null|LoggerInterface $logger = n ); $this->_coreFiles = new CoreFiles( + $this, $this->getOutputPath(), PHPFHIR_TEMPLATE_CORE_DIR, $this->getFullyQualifiedName(true), diff --git a/src/CoreFile.php b/src/CoreFile.php index 8892be28..099b2d44 100644 --- a/src/CoreFile.php +++ b/src/CoreFile.php @@ -18,6 +18,7 @@ * limitations under the License. */ +use DCarbone\PHPFHIR\Builder\Imports; use DCarbone\PHPFHIR\Utilities\NameUtils; class CoreFile @@ -41,12 +42,16 @@ class CoreFile /** @var bool */ private bool $_isAutoloader = false; + /** @var \DCarbone\PHPFHIR\Builder\Imports */ + private Imports $_imports; + /** + * @param \DCarbone\PHPFHIR\Config $config * @param string $templateFile * @param string $outDir - * @param string $baseNS + * @param string $namespace */ - public function __construct(string $templateFile, string $outDir, string $baseNS) + public function __construct(Config $config, string $templateFile, string $outDir, string $namespace) { $this->_templateFile = $templateFile; @@ -59,7 +64,7 @@ public function __construct(string $templateFile, string $outDir, string $baseNS // classname suffix $suffix = NameUtils::phpNameFormat($this->_type); - $this->_namespace = ltrim($baseNS, PHPFHIR_NAMESPACE_SEPARATOR); + $this->_namespace = trim($namespace, PHPFHIR_NAMESPACE_SEPARATOR); if ('class' === $this->_type) { // 'class' types do have suffix @@ -78,6 +83,16 @@ public function __construct(string $templateFile, string $outDir, string $baseNS // build full filepath $this->_filepath = $outDir . DIRECTORY_SEPARATOR . "{$this->_entityName}.php"; + + $this->_imports = new Imports($config, $this->_namespace, $this->_entityName); + } + + /** + * @return \DCarbone\PHPFHIR\Builder\Imports + */ + public function getImports(): Imports + { + return $this->_imports; } /** diff --git a/src/CoreFiles.php b/src/CoreFiles.php index f841277f..612ed684 100644 --- a/src/CoreFiles.php +++ b/src/CoreFiles.php @@ -31,11 +31,12 @@ class CoreFiles private array $_files; /** + * @param \DCarbone\PHPFHIR\Config $config * @param string $outputDir * @param string $templateDir * @param string $baseNS */ - public function __construct(string $outputDir, string $templateDir, string $baseNS) + public function __construct(Config $config, string $outputDir, string $templateDir, string $baseNS) { $this->_outputDir = realpath($outputDir); $this->_templateDir = realpath($templateDir); @@ -54,7 +55,7 @@ public function __construct(string $outputDir, string $templateDir, string $base $outDir .= DIRECTORY_SEPARATOR . NameUtils::templateFilenameToPHPName($outNS, PHPFHIR_NAMESPACE_SEPARATOR, DIRECTORY_SEPARATOR); - $this->_files[] = new CoreFile($fpath, $outDir, $outNS); + $this->_files[] = new CoreFile($config, $fpath, $outDir, $outNS); } } diff --git a/src/Utilities/ExceptionUtils.php b/src/Utilities/ExceptionUtils.php index d946cd59..b2851e0a 100644 --- a/src/Utilities/ExceptionUtils.php +++ b/src/Utilities/ExceptionUtils.php @@ -22,10 +22,6 @@ use DCarbone\PHPFHIR\Version\Definition\Property; use DCarbone\PHPFHIR\Version\Definition\Type; -/** - * Class ExceptionUtils - * @package DCarbone\PHPFHIR\Utilities - */ class ExceptionUtils { /** diff --git a/src/Utilities/ImportUtils.php b/src/Utilities/ImportUtils.php new file mode 100644 index 00000000..5feff932 --- /dev/null +++ b/src/Utilities/ImportUtils.php @@ -0,0 +1,123 @@ +getGenerator() as $import) { + if ($import->requiresImport()) { + $stmts[] = "use {$import->getFullyQualifiedName(false)};"; + } + } + if ([] === $stmts) { + return ''; + } + return implode("\n", $stmts) . "\n"; + } + + public static function buildVersionTypeImports(Type $type): void + { + $imports = $type->getImports(); + // immediately add self + $imports->addImport($type->getFullyQualifiedNamespace(false), $type->getClassName()); + + $typeNS = $type->getFullyQualifiedNamespace(false); + $configNS = $type->getConfig()->getFullyQualifiedName(false); + + $typeKind = $type->getKind(); + + $allProperties = $type->getAllPropertiesIndexedIterator(); + + if (!$type->isAbstract()) { + $imports->addCoreFileImports(PHPFHIR_CLASSNAME_XML_WRITER); + $imports->addCoreFileImports(PHPFHIR_ENUM_XML_LOCATION); + } + + $imports->addVersionCoreFileImport(PHPFHIR_CLASSNAME_VERSION); + $imports->addVersionCoreFileImport(PHPFHIR_CLASSNAME_VERSION_CONSTANTS); + $imports->addCoreFileImports(PHPFHIR_CLASSNAME_UNSERIALIZE_CONFIG); + $imports->addCoreFileImports(PHPFHIR_CLASSNAME_SERIALIZE_CONFIG); + + $imports->addCoreFileImports(PHPFHIR_INTERFACE_TYPE); + + foreach ($type->getDirectlyImplementedInterfaces() as $interface => $namespace) { + $imports->addImport($namespace, $interface); + } + + foreach ($type->getDirectlyUsedTraits() as $trait => $namespace) { + $imports->addImport($namespace, $trait); + } + + if (($type->isCommentContainer() && !$type->hasCommentContainerParent()) || + $type->hasLocalPropertiesWithValidations() || + ($typeKind->isOneOf(TypeKindEnum::PRIMITIVE) && !$type->hasPrimitiveParent())) { + $imports->addCoreFileImports(PHPFHIR_CLASSNAME_CONSTANTS); + } + + if ($parentType = $type->getParentType()) { + $pns = $parentType->getFullyQualifiedNamespace(false); + $imports->addImport($pns, $parentType->getClassName()); + } + + if ($type->hasLocalPropertiesWithValidations()) { + $imports->addCoreFileImports(PHPFHIR_CLASSNAME_VALIDATOR); + } + + if ($restrictionBaseType = $type->getRestrictionBaseFHIRType()) { + $rns = $restrictionBaseType->getFullyQualifiedNamespace(false); + $imports->addImport($rns, $restrictionBaseType->getClassName()); + } + + foreach ($allProperties as $property) { + $propertyType = $property->getValueFHIRType(); + if (null === $propertyType) { + continue; + } + + $ptk = $propertyType->getKind(); + + if ($property->isOverloaded() && !$ptk->isOneOf(TypeKindEnum::PRIMITIVE, TypeKindEnum::LIST)) { + continue; + } + + if ($ptk->isOneOf(TypeKindEnum::RESOURCE_CONTAINER, TypeKindEnum::RESOURCE_INLINE) && + $typeNS !== $configNS) { + $imports->addCoreFileImports(PHPFHIR_CLASSNAME_CONSTANTS); + $imports->addVersionCoreFileImport(PHPFHIR_INTERFACE_VERSION_CONTAINED_TYPE); + $imports->addVersionCoreFileImport(PHPFHIR_CLASSNAME_VERSION_TYPE_MAP); + $imports->addVersionCoreFileImport(PHPFHIR_CLASSNAME_VERSION); + } else { + if ($ptk === TypeKindEnum::PRIMITIVE_CONTAINER) { + $primType = $propertyType->getLocalProperties()->getProperty('value')->getValueFHIRType(); + $imports->addImport($primType->getFullyQualifiedNamespace(false), $primType->getClassName()); + } + + $propertyTypeNS = $propertyType->getFullyQualifiedNamespace(false); + $imports->addImport($propertyTypeNS, $propertyType->getClassName()); + } + } + } +} \ No newline at end of file diff --git a/src/Version.php b/src/Version.php index 8fc962fb..8105f529 100644 --- a/src/Version.php +++ b/src/Version.php @@ -112,6 +112,7 @@ public function __construct(Config $config, string $name, array $params = []) $this->_sourceMetadata = new SourceMetadata($config, $this); $this->_coreFiles = new CoreFiles( + $this->_config, $config->getOutputPath(), PHPFHIR_TEMPLATE_VERSIONS_CORE_DIR, $this->getFullyQualifiedName(true), diff --git a/src/Version/Definition/Type.php b/src/Version/Definition/Type.php index b57b0542..38d67b76 100644 --- a/src/Version/Definition/Type.php +++ b/src/Version/Definition/Type.php @@ -18,6 +18,7 @@ * limitations under the License. */ +use DCarbone\PHPFHIR\Version\VersionImports; use DCarbone\PHPFHIR\Config; use DCarbone\PHPFHIR\Enum\PrimitiveTypeEnum; use DCarbone\PHPFHIR\Enum\TestTypeEnum; @@ -98,9 +99,8 @@ class Type private bool $valueContainer = false; /** @var bool */ private bool $commentContainer = false; - - /** @var \DCarbone\PHPFHIR\Version\Definition\TypeImports */ - private TypeImports $imports; + /** @var \DCarbone\PHPFHIR\Version\VersionImports */ + private VersionImports $imports; /** * Type constructor. @@ -128,7 +128,11 @@ public function __construct( $this->sourceFilename = $sourceFilename; $this->localProperties = new Properties($config, $version, $this); $this->enumeration = new Enumeration(); - $this->imports = new TypeImports($this); + $this->imports = new VersionImports( + $version, + $this->getFullyQualifiedNamespace(false), + $this->getClassName(), + ); } /** @@ -166,9 +170,9 @@ public function getFHIRName(): string } /** - * @return \DCarbone\PHPFHIR\Version\Definition\TypeImports + * @return \DCarbone\PHPFHIR\Version\VersionImports */ - public function getImports(): TypeImports + public function getImports(): VersionImports { return $this->imports; } @@ -370,19 +374,20 @@ public function hasLocalPropertiesWithValidations(): bool /** * @return \DCarbone\PHPFHIR\Version\Definition\Property[] */ - public function getAllPropertiesIterator(): iterable + public function getAllPropertiesIndexedIterator(): iterable { $properties = []; foreach ($this->getLocalProperties()->getLocalPropertiesIterator() as $property) { $properties[$property->getName()] = $property; } foreach ($this->getParentTypes() as $parentType) { - foreach ($parentType->getAllPropertiesIterator() as $property) { + foreach ($parentType->getAllPropertiesIndexedIterator() as $property) { if (!isset($properties[$property->getName()])) { $properties[$property->getName()] = $property; } } } + // this returns an \SplFixedArray to provide an indexed iterator return \SplFixedArray::fromArray($properties, preserveKeys: false); } diff --git a/src/Version/Definition/TypeImports.php b/src/Version/Definition/TypeImports.php deleted file mode 100644 index 10a5bbf6..00000000 --- a/src/Version/Definition/TypeImports.php +++ /dev/null @@ -1,267 +0,0 @@ -type = $type; - } - - /** - * @param string $classname - * @param string $namespace - */ - public function addImport(string $classname, string $namespace): void - { - $requiresImport = !str_starts_with($classname, '\\') && - ltrim($namespace, '\\') !== $this->type->getFullyQualifiedNamespace(false); - - if (isset($this->imports[$classname])) { - // if we have already seen this type, move on. - if ($this->imports[$classname]->getNamespace() === $namespace) { - return; - } - - // if there is a conflicting imported type here... - $aliasName = $this->findNextAliasName($classname, $namespace); - $this->imports[$aliasName] = new TypeImport($classname, $namespace, true, $aliasName, $requiresImport); - return; - } - - if ($classname === $this->type->getClassName() && - $namespace !== $this->type->getFullyQualifiedNamespace(false)) { - // if the imported type has the same class name as the direct type, but a different namespace - $aliasName = $this->findNextAliasName($classname, $namespace); - $this->imports[$aliasName] = new TypeImport($classname, $namespace, true, $aliasName, $requiresImport); - return; - } - - // otherwise, go ahead and add to map. - $this->imports[$classname] = new TypeImport($classname, $namespace, false, '', $requiresImport); - } - - public function addCoreFileImport(string $entityName): void - { - $coreFile = $this->type->getVersion()->getConfig()->getCoreFiles()->getCoreFileByEntityName($entityName); - $this->addImport($coreFile->getEntityName(), $coreFile->getNamespace()); - } - - public function addVersionCoreFileImport(string $entityName): void - { - $coreFile = $this->type->getVersion()->getCoreFiles()->getCoreFileByEntityName($entityName); - $this->addImport($coreFile->getEntityName(), $coreFile->getNamespace()); - } - - /** - * @return \DCarbone\PHPFHIR\Version\Definition\TypeImport[] - */ - public function getIterator(): iterable - { - $this->buildImports(); - return new \ArrayIterator($this->imports); - } - - /** - * @param \DCarbone\PHPFHIR\Version\Definition\Type $type - * @return \DCarbone\PHPFHIR\Version\Definition\TypeImport|null - */ - public function getImportByType(Type $type): ?TypeImport - { - $this->buildImports(); - $fqn = $type->getFullyQualifiedClassName(false); - foreach ($this->imports as $import) { - if ($import->getFullyQualifiedClassname(false) === $fqn) { - return $import; - } - } - return null; - } - - /** - * @param string $classname - * @param string $namespace - * @return \DCarbone\PHPFHIR\Version\Definition\TypeImport|null - */ - public function getImportByClassAndNamespace(string $classname, string $namespace): ?TypeImport - { - $this->buildImports(); - foreach ($this->imports as $import) { - if ($import->getNamespace() === $namespace && $import->getClassname() === $classname) { - return $import; - } - } - return null; - } - - /** - * @param string $aliasName - * @return \DCarbone\PHPFHIR\Version\Definition\TypeImport|null - */ - public function getImportByAlias(string $aliasName): ?TypeImport - { - $this->buildImports(); - return $this->imports[$aliasName] ?? null; - } - - /** - * @return int - */ - public function count(): int - { - $this->buildImports(); - return count($this->imports); - } - - /** - * TODO: come up with better alias scheme... - * - * @param string $classname - * @param string $namespace - * @return string - */ - private function findNextAliasName(string $classname, string $namespace): string - { - $i = 1; - $aliasName = "{$classname}{$i}"; - while (null !== $this->getImportByAlias($aliasName)) { - $aliasName = "{$classname}{++$i}"; - } - return $aliasName; - } - - /** - * Attempts to build succinct list of imports used by this type. Currently flawed, results in some unused imports - * to be defined. Will need to be revisited. - * - * @return void - */ - private function buildImports(): void - { - if ($this->parsed) { - return; - } - $this->parsed = true; - - // immediately add self - $this->addImport($this->type->getClassName(), $this->type->getFullyQualifiedNamespace(false)); - - $typeNS = $this->type->getFullyQualifiedNamespace(false); - $configNS = $this->type->getConfig()->getFullyQualifiedName(false); - - $typeKind = $this->type->getKind(); - - $allProperties = $this->type->getAllPropertiesIterator(); - - if (!$this->type->isAbstract()) { - $this->addCoreFileImport(PHPFHIR_CLASSNAME_XML_WRITER); - $this->addCoreFileImport(PHPFHIR_ENUM_XML_LOCATION); - } - - $this->addVersionCoreFileImport(PHPFHIR_CLASSNAME_VERSION); - $this->addVersionCoreFileImport(PHPFHIR_CLASSNAME_VERSION_CONSTANTS); - $this->addCoreFileImport(PHPFHIR_CLASSNAME_UNSERIALIZE_CONFIG); - $this->addCoreFileImport(PHPFHIR_CLASSNAME_SERIALIZE_CONFIG); - - $this->addCoreFileImport(PHPFHIR_INTERFACE_TYPE); - - foreach ($this->type->getDirectlyImplementedInterfaces() as $interface => $namespace) { - $this->addImport($interface, $namespace); - } - - foreach ($this->type->getDirectlyUsedTraits() as $trait => $namespace) { - $this->addImport($trait, $namespace); - } - - if (($this->type->isCommentContainer() && !$this->type->hasCommentContainerParent()) || - $this->type->hasLocalPropertiesWithValidations() || - ($typeKind->isOneOf(TypeKindEnum::PRIMITIVE) && !$this->type->hasPrimitiveParent())) { - $this->addCoreFileImport(PHPFHIR_CLASSNAME_CONSTANTS); - } - - if ($parentType = $this->type->getParentType()) { - $pns = $parentType->getFullyQualifiedNamespace(false); - $this->addImport($parentType->getClassName(), $pns); - } - - if ($this->type->hasLocalPropertiesWithValidations()) { - $this->addCoreFileImport(PHPFHIR_CLASSNAME_VALIDATOR); - } - - if ($restrictionBaseType = $this->type->getRestrictionBaseFHIRType()) { - $rns = $restrictionBaseType->getFullyQualifiedNamespace(false); - $this->addImport($restrictionBaseType->getClassName(), $rns); - } - - foreach ($allProperties as $property) { - $propertyType = $property->getValueFHIRType(); - if (null === $propertyType) { - continue; - } - - $ptk = $propertyType->getKind(); - - if ($property->isOverloaded() && !$ptk->isOneOf(TypeKindEnum::PRIMITIVE, TypeKindEnum::LIST)) { - continue; - } - - if ($ptk->isOneOf(TypeKindEnum::RESOURCE_CONTAINER, TypeKindEnum::RESOURCE_INLINE) && - $typeNS !== $configNS) { - $this->addCoreFileImport(PHPFHIR_CLASSNAME_CONSTANTS); - $this->addVersionCoreFileImport(PHPFHIR_INTERFACE_VERSION_CONTAINED_TYPE); - $this->addVersionCoreFileImport(PHPFHIR_CLASSNAME_VERSION_TYPE_MAP); - $this->addVersionCoreFileImport(PHPFHIR_CLASSNAME_VERSION); - } else { - if ($ptk === TypeKindEnum::PRIMITIVE_CONTAINER) { - $primType = $propertyType->getLocalProperties()->getProperty('value')->getValueFHIRType(); - $this->addImport($primType->getClassName(), $primType->getFullyQualifiedNamespace(false)); - } - - $propertyTypeNS = $propertyType->getFullyQualifiedNamespace(false); - $this->addImport($propertyType->getClassName(), $propertyTypeNS); - } - } - - uasort( - $this->imports, - function (TypeImport $a, TypeImport $b) { - return strnatcasecmp($a->getFullyQualifiedClassname(false), $b->getFullyQualifiedClassname(false)); - } - ); - } -} \ No newline at end of file diff --git a/src/Version/VersionImports.php b/src/Version/VersionImports.php new file mode 100644 index 00000000..5f1aa667 --- /dev/null +++ b/src/Version/VersionImports.php @@ -0,0 +1,49 @@ +getConfig(), $localNamespace, $localName); + + $this->_version = $version; + } + + public function addVersionCoreFileImport(string ...$entityNames): self + { + foreach ($entityNames as $en) { + $coreFile = $this->_version->getCoreFiles()->getCoreFileByEntityName($en); + $this->addImport($coreFile->getNamespace(), $coreFile->getEntityName()); + } + return $this; + } +} \ No newline at end of file diff --git a/template/core/class_autoloader.php b/template/core/class_autoloader.php index 9132908b..bb4414e1 100644 --- a/template/core/class_autoloader.php +++ b/template/core/class_autoloader.php @@ -23,8 +23,6 @@ $coreFiles = $config->getCoreFiles(); -$constsClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_CONSTANTS); - ob_start(); echo 'declare(strict_types=1); @@ -33,8 +31,6 @@ getBasePHPFHIRCopyrightComment(false); ?> -use getFullyQualifiedName(false); ?>; - abstract class { diff --git a/template/core/class_factory.php b/template/core/class_factory.php index eed9a772..1653214f 100644 --- a/template/core/class_factory.php +++ b/template/core/class_factory.php @@ -16,9 +16,18 @@ * limitations under the License. */ +use DCarbone\PHPFHIR\Utilities\ImportUtils; + /** @var \DCarbone\PHPFHIR\Config $config */ /** @var \DCarbone\PHPFHIR\CoreFile $coreFile */ +$imports = $coreFile->getImports(); + +$imports->addCoreFileImports( + PHPFHIR_CLASSNAME_FACTORY_CONFIG, + PHPFHIR_INTERFACE_VERSION, +); + $coreFiles = $config->getCoreFiles(); $factConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_FACTORY_CONFIG); @@ -31,6 +40,7 @@ getBasePHPFHIRCopyrightComment(false); ?> + /** * Class diff --git a/template/core/class_version_config.php b/template/core/class_version_config.php index f528961c..509c6b1d 100644 --- a/template/core/class_version_config.php +++ b/template/core/class_version_config.php @@ -16,9 +16,22 @@ * limitations under the License. */ +use DCarbone\PHPFHIR\Utilities\ImportUtils; + /** @var \DCarbone\PHPFHIR\Config $config */ /** @var \DCarbone\PHPFHIR\CoreFile $coreFile */ +$imports = $coreFile->getImports(); +$imports->addCoreFileImports( + PHPFHIR_CLASSNAME_SERIALIZE_CONFIG, + PHPFHIR_CLASSNAME_UNSERIALIZE_CONFIG, +); + +$coreFiles = $config->getCoreFiles(); + +$serializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_SERIALIZE_CONFIG); +$unserializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_UNSERIALIZE_CONFIG); + ob_start(); echo 'declare(strict_types=1); @@ -27,6 +40,8 @@ getBasePHPFHIRCopyrightComment(false); ?> + + class implements { @@ -41,10 +56,10 @@ class implements PHPFHIR_FHIR_XMLNS, ]; - /** @var getFullyQualifiedName(true, PHPFHIR_CLASSNAME_UNSERIALIZE_CONFIG); ?> */ + /** @var getFullyQualifiedName(true); ?> */ private $unserializeConfig; - /** @var getFullyQualifiedName(true, PHPFHIR_CLASSNAME_SERIALIZE_CONFIG); ?> */ + /** @var getFullyQualifiedName(true); ?> */ private $serializeConfig; /** @@ -68,7 +83,7 @@ public function __construct(array $config = []) } /** - * @param array|getFullyQualifiedName(true, PHPFHIR_CLASSNAME_UNSERIALIZE_CONFIG); ?> $config + * @param array|getFullyQualifiedName(true); ?> $config * @return self */ public function setUnserializeConfig(array| $config): self @@ -81,20 +96,17 @@ public function setUnserializeConfig(array|getFullyQualifiedName(true, PHPFHIR_CLASSNAME_UNSERIALIZE_CONFIG); ?> + * @return getFullyQualifiedName(true); ?> */ public function getUnserializeConfig(): { - if (!isset($this->unserializeConfig)) { - $this->unserializeConfig = new (self::_DEFAULT_UNSERIALIZE_CONFIG); - } return $this->unserializeConfig; } /** - * @param array|getFullyQualifiedName(true, PHPFHIR_CLASSNAME_SERIALIZE_CONFIG); ?> $config + * @param array|getFullyQualifiedName(true); ?> $config * @return self */ public function setSerializeConfig(array| $config): self @@ -107,15 +119,12 @@ public function setSerializeConfig(array|getFullyQualifiedName(true, PHPFHIR_CLASSNAME_SERIALIZE_CONFIG); ?> + * @return getFullyQualifiedName(true); ?> */ public function getSerializeConfig(): { - if (!isset($this->serializeConfig)) { - $this->serializeConfig = new (self::_DEFAULT_SERIALIZE_CONFIG); - } return $this->serializeConfig; } } diff --git a/template/core/client/class_client.php b/template/core/client/class_client.php index 48ec515d..c02f4780 100644 --- a/template/core/client/class_client.php +++ b/template/core/client/class_client.php @@ -16,10 +16,20 @@ * limitations under the License. */ +use DCarbone\PHPFHIR\Utilities\ImportUtils; + /** @var \DCarbone\PHPFHIR\Config $config */ /** @var \DCarbone\PHPFHIR\CoreFile $coreFile */ $coreFiles = $config->getCoreFiles(); +$imports = $coreFile->getImports(); + +$imports->addCoreFileImports( + PHPFHIR_CLASSNAME_CLIENT_CONFIG, + PHPFHIR_CLASSNAME_CLIENT_REQUEST, + PHPFHIR_CLASSNAME_CLIENT_RESPONSE, + PHPFHIR_ENUM_CLIENT_HTTP_METHOD, +); $confClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_CLIENT_CONFIG); $reqClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_CLIENT_REQUEST); @@ -34,6 +44,8 @@ getBasePHPFHIRCopyrightComment(false); ?> + + /** * Class @@ -53,7 +65,6 @@ class implements 'php-fhir client (build: getStandardDate(); ?>;)', ]; - /** @var getFullyQualifiedName(true); ?> */ protected $_config; /** @@ -69,12 +80,6 @@ public function __construct(string|_config = $config; } - /** - * Return configuration used by this client. - * - * @return getFullyQualifiedName(true); ?> - - */ public function getConfig(): { @@ -152,14 +157,6 @@ public function exec( $request): return $rc; } - /** - * @param string|getFullyQualifiedName(true); ?> $method - * @param string $path - * @param array $queryParams - * @param array $curlOpts - * @return getFullyQualifiedName(true); ?> - - */ private function _exec(string|getEntityName(); ?> $method, string $path, array $queryParams = [], array $curlOpts = []): { @@ -171,78 +168,36 @@ private function _exec(string|getEntityName(); ?> $met return $this->exec($req); } - /** - * @param string $path - * @param array $queryParams - * @param array $curlOpts - * @return getFullyQualifiedName(true); ?> - - */ public function get(string $path, array $queryParams = [], array $curlOpts = []): { return $this->_exec(getEntityName(); ?>::GET, $path, $queryParams, $curlOpts); } - /** - * @param string $path - * @param array $queryParams - * @param array $curlOpts - * @return getFullyQualifiedName(true); ?> - - */ public function put(string $path, array $queryParams = [], array $curlOpts = []): { return $this->_exec(getEntityName(); ?>::PUT, $path, $queryParams, $curlOpts); } - /** - * @param string $path - * @param array $queryParams - * @param array $curlOpts - * @return getFullyQualifiedName(true); ?> - - */ public function post(string $path, array $queryParams = [], array $curlOpts = []): { return $this->_exec(getEntityName(); ?>::POST, $path, $queryParams, $curlOpts); } - /** - * @param string $path - * @param array $queryParams - * @param array $curlOpts - * @return getFullyQualifiedName(true); ?> - - */ public function patch(string $path, array $queryParams = [], array $curlOpts = []): { return $this->_exec(getEntityName(); ?>::PATCH, $path, $queryParams, $curlOpts); } - /** - * @param string $path - * @param array $queryParams - * @param array $curlOpts - * @return getFullyQualifiedName(true); ?> - - */ public function delete(string $path, array $queryParams = [], array $curlOpts = []): { return $this->_exec(getEntityName(); ?>::DELETE, $path, $queryParams, $curlOpts); } - /** - * @param string $path - * @param array $queryParams - * @param array $curlOpts - * @return getFullyQualifiedName(true); ?> - - */ public function head(string $path, array $queryParams = [], array $curlOpts = []): { diff --git a/template/core/client/exception_client_error.php b/template/core/client/exception_client_error.php index 9d5f1fed..283e2ee8 100644 --- a/template/core/client/exception_client_error.php +++ b/template/core/client/exception_client_error.php @@ -27,7 +27,7 @@ getBasePHPFHIRCopyrightComment(false); ?> -class extends +class extends { public function __construct( $rc) { diff --git a/template/core/interface_type.php b/template/core/interface_type.php index 05854731..ec265c61 100644 --- a/template/core/interface_type.php +++ b/template/core/interface_type.php @@ -20,6 +20,16 @@ /** @var \DCarbone\PHPFHIR\Config $config */ /** @var \DCarbone\PHPFHIR\CoreFile $coreFile */ +use DCarbone\PHPFHIR\Utilities\ImportUtils; + +$imports = $coreFile->getImports(); + +$imports->addCoreFileImports( + PHPFHIR_CLASSNAME_SERIALIZE_CONFIG, + PHPFHIR_CLASSNAME_UNSERIALIZE_CONFIG, + PHPFHIR_CLASSNAME_XML_WRITER, +); + $coreFiles = $config->getCoreFiles(); $serializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_SERIALIZE_CONFIG); @@ -34,9 +44,7 @@ getBasePHPFHIRCopyrightComment(false); ?> -use getFullyQualifiedName(false); ?>; -use getFullyQualifiedName(false); ?>; -use getFullyQualifiedName(false); ?>; + interface extends \JsonSerializable { diff --git a/template/core/interface_version_config.php b/template/core/interface_version_config.php index 7949dc86..d9d965ad 100644 --- a/template/core/interface_version_config.php +++ b/template/core/interface_version_config.php @@ -19,6 +19,14 @@ /** @var \DCarbone\PHPFHIR\Config $config */ /** @var \DCarbone\PHPFHIR\CoreFile $coreFile */ +use DCarbone\PHPFHIR\Utilities\ImportUtils; + +$imports = $coreFile->getImports(); +$imports->addCoreFileImports( + PHPFHIR_CLASSNAME_SERIALIZE_CONFIG, + PHPFHIR_CLASSNAME_UNSERIALIZE_CONFIG, +); + $coreFiles = $config->getCoreFiles(); $serializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_SERIALIZE_CONFIG); @@ -32,8 +40,7 @@ getBasePHPFHIRCopyrightComment(false); ?> -use getFullyQualifiedName(false); ?>; -use getFullyQualifiedName(false); ?>; + interface diff --git a/template/core/validation/class_validator.php b/template/core/validation/class_validator.php index 4966947e..d72d02f6 100644 --- a/template/core/validation/class_validator.php +++ b/template/core/validation/class_validator.php @@ -19,9 +19,17 @@ /** @var \DCarbone\PHPFHIR\Config $config */ /** @var \DCarbone\PHPFHIR\CoreFile $coreFile */ +use DCarbone\PHPFHIR\Utilities\ImportUtils; + $coreFiles = $config->getCoreFiles(); +$imports = $coreFile->getImports(); + +$imports->addCoreFileImports( + PHPFHIR_CLASSNAME_CONSTANTS, + PHPFHIR_INTERFACE_TYPE, + PHPFHIR_INTERFACE_PRIMITIVE_TYPE, +); -$constsClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_CONSTANTS); $typeInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_INTERFACE_TYPE); $pimitiveTypeInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_INTERFACE_PRIMITIVE_TYPE); @@ -33,9 +41,7 @@ getBasePHPFHIRCopyrightComment(false); ?> -use getFullyQualifiedName(false); ?>; -use getFullyQualifiedName(false); ?>; -use getFullyQualifiedName(false); ?>; + class diff --git a/template/versions/core/class_autoloader.php b/template/versions/core/class_autoloader.php index 57b39d98..5a6da8e6 100644 --- a/template/versions/core/class_autoloader.php +++ b/template/versions/core/class_autoloader.php @@ -38,7 +38,7 @@ abstract class /** @var array */ private const _CLASS_MAP = [ // version core types -getCoreFiles()->getIterator() as $coreFile): if ($coreFile->isAutoloader() || $coreFile->isTest()) { continue; } ?> +getCoreFiles()->getGenerator() as $coreFile): if ($coreFile->isAutoloader() || $coreFile->isTest()) { continue; } ?> 'getFullyQualifiedName(false); ?>' => getFullyQualifiedName(false), $coreFile->getFullyQualifiedName(false), diff --git a/template/versions/core/class_version.php b/template/versions/core/class_version.php index 55af3f4a..74f9dc89 100644 --- a/template/versions/core/class_version.php +++ b/template/versions/core/class_version.php @@ -20,6 +20,16 @@ /** @var \DCarbone\PHPFHIR\CoreFile $coreFile */ $config = $version->getConfig(); +$coreFiles = $config->getCoreFiles(); +$versionCoreFiles = $version->getCoreFiles(); + +$clientInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_INTERFACE_CLIENT_CLIENT); +$versionInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_INTERFACE_VERSION); +$versionConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_VERSION_CONFIG); +$versionConfigInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_INTERFACE_VERSION_CONFIG); +$versionTypeMapInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_INTERFACE_VERSION_TYPE_MAP); + +$versionTypeMapClass = $versionCoreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_VERSION_TYPE_MAP); ob_start(); echo 'declare(strict_types=1); @@ -29,10 +39,10 @@ getSourceMetadata()->getFullPHPFHIRCopyrightComment(); ?> -use getFullyQualifiedName(false, PHPFHIR_INTERFACE_VERSION); ?>; -use getFullyQualifiedName(false, PHPFHIR_CLASSNAME_VERSION_CONFIG); ?>; -use getFullyQualifiedName(false, PHPFHIR_INTERFACE_VERSION_CONFIG); ?>; -use getFullyQualifiedName(false, PHPFHIR_INTERFACE_VERSION_TYPE_MAP); ?>; +use getFullyQualifiedName(false); ?>; +use getFullyQualifiedName(false); ?>; +use getFullyQualifiedName(false); ?>; +use getFullyQualifiedName(false); ?>; class implements @@ -43,24 +53,24 @@ class implements getDefaultConfig()->toArray(), 1); ?>; - /** @var getFullyQualifiedName(true, PHPFHIR_INTERFACE_VERSION_CONFIG); ?> */ + /** @var getFullyQualifiedName(true); ?> */ private $_config; - /** @var getFullyQualifiedName(true, PHPFHIR_CLASSNAME_VERSION_TYPE_MAP); ?> */ + /** @var getFullyQualifiedName(true); ?> */ private static $_typeMap; /** * Constructor - * @param null|array|getFullyQualifiedName(true, PHPFHIR_INTERFACE_VERSION_CONFIG); ?> $config + * @param null|array|getFullyQualifiedName(true); ?> $config */ public function __construct(null|array| $config = null) { if (!is_object($config)) { $config = new (array_merge(self::_GENERATED_CONFIG, (array)$config)); - } else if (!($config instanceof )) { + } else if (!($config instanceof )) { throw new \InvalidArgumentException(sprintf( '$config must be an instance of \\%s, %s given', - ::class, + ::class, get_class($config) )); } @@ -92,7 +102,7 @@ public function getSourceGenerationDate(): string } /** - * @return getFullyQualifiedName(true, PHPFHIR_INTERFACE_VERSION_CONFIG); ?> + * @return getFullyQualifiedName(true); ?> */ public function getConfig(): @@ -102,7 +112,7 @@ public function getConfig(): } /** - * @return getFullyQualifiedName(true, PHPFHIR_CLASSNAME_VERSION_TYPE_MAP); ?> + * @return getFullyQualifiedName(true); ?> */ public function getTypeMap(): diff --git a/template/versions/core/class_version_api_client.php b/template/versions/core/class_version_api_client.php index e7b016d6..74f2c4bd 100644 --- a/template/versions/core/class_version_api_client.php +++ b/template/versions/core/class_version_api_client.php @@ -20,9 +20,20 @@ /** @var \DCarbone\PHPFHIR\CoreFile $coreFile */ $config = $version->getConfig(); +$coreFiles = $config->getCoreFiles(); +$clientInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_INTERFACE_CLIENT_CLIENT); +$clientResponseFormatEnum = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENUM_CLIENT_RESPONSE_FORMAT); +$clientSortEnum = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENUM_CLIENT_SORT); +$clientRequestClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_CLIENT_REQUEST); +$clientResponseClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_CLIENT_RESPONSE); +$clientErrorException = $coreFiles->getCoreFileByEntityName(PHPFHIR_EXCEPTION_CLIENT_ERROR); +$clientUnexpectedResponseCodeException = $coreFiles->getCoreFileByEntityName(PHPFHIR_EXCEPTION_CLIENT_UNEXPECTED_RESPONSE_CODE); +$responseParserClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_RESPONSE_PARSER); +$typeInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_INTERFACE_TYPE); + +$versionCoreFiles = $version->getCoreFiles(); + $types = $version->getDefinition()->getTypes(); -$namespace = $version->getFullyQualifiedName(false); -$bundleType = $types->getBundleType(); $idType = $types->getTypeByName('id'); $idPrimitiveType = $types->getTypeByName('id-primitive'); @@ -35,16 +46,17 @@ getSourceMetadata()->getFullPHPFHIRCopyrightComment(); ?> -use getFullyQualifiedName(false, PHPFHIR_INTERFACE_CLIENT_CLIENT); ?>; -use getFullyQualifiedName(false, PHPFHIR_ENUM_CLIENT_RESPONSE_FORMAT); ?>; -use getFullyQualifiedName(false, PHPFHIR_CLASSNAME_CLIENT_REQUEST); ?>; -use getFullyQualifiedName(false, PHPFHIR_CLASSNAME_CLIENT_RESPONSE); ?>; -use getFullyQualifiedName(false, PHPFHIR_EXCEPTION_CLIENT_NETWORK_ERROR); ?>; -use getFullyQualifiedName(false, PHPFHIR_EXCEPTION_CLIENT_UNEXPECTED_RESPONSE_CODE); ?>; -use getFullyQualifiedName(false, PHPFHIR_ENUM_CLIENT_SORT); ?>; -use getFullyQualifiedName(false, PHPFHIR_CLASSNAME_RESPONSE_PARSER); ?>; -use getFullyQualifiedName(false, PHPFHIR_INTERFACE_TYPE); ?>; +use getFullyQualifiedName(false); ?>; +use getFullyQualifiedName(false); ?>; +use getFullyQualifiedName(false); ?>; +use getFullyQualifiedName(false); ?>; +use getFullyQualifiedName(false); ?>; +use getFullyQualifiedName(false); ?>; +use getFullyQualifiedName(false); ?>; +use getFullyQualifiedName(false); ?>; +use getFullyQualifiedName(false); ?>; use getFullyQualifiedClassName(false); ?>; +use getFullyQualifiedClassName(false); ?>; class @@ -155,7 +167,7 @@ public function read(string| $resourceTy /** * @param getFullyQualifiedName(true, PHPFHIR_CLASSNAME_CLIENT_RESPONSE); ?> $rc - * @throws getFullyQualifiedName(true, PHPFHIR_EXCEPTION_CLIENT_NETWORK_ERROR); ?> + * @throws getFullyQualifiedName(true, PHPFHIR_EXCEPTION_CLIENT_ERROR); ?> * @throws getFullyQualifiedName(true, PHPFHIR_EXCEPTION_CLIENT_UNEXPECTED_RESPONSE_CODE); ?> @@ -163,7 +175,7 @@ public function read(string| $resourceTy protected function _requireOK( $rc): void { if (isset($rc->err)) { - throw new ($rc); + throw new ($rc); } if (!isset($rc->code) || self::_STATUS_OK !== $rc->code) { throw new ($rc, self::_STATUS_OK); diff --git a/template/versions/types/class_default.php b/template/versions/types/class_default.php index df260ba0..010b5ab4 100644 --- a/template/versions/types/class_default.php +++ b/template/versions/types/class_default.php @@ -110,7 +110,7 @@ self::getFieldConstantName(); ?> => [ $v) : ?> - :: => , + :: => , ], declare(strict_types=1); @@ -31,15 +32,10 @@ getImports()->getIterator() as $import) { - if ($import->isRequiresImport()) { - echo $import->getUseStatement(); - $imported++; - } -} -if (0 !== $imported) { - echo "\n"; -} +ImportUtils::buildVersionTypeImports($type); + +echo ImportUtils::compileImportStatements($type->getImports()); + +echo "\n"; return ob_get_clean(); diff --git a/template/versions/types/serialization/xml.php b/template/versions/types/serialization/xml.php index 9b641602..27fb7ea0 100644 --- a/template/versions/types/serialization/xml.php +++ b/template/versions/types/serialization/xml.php @@ -27,7 +27,7 @@ $xmlName = NameUtils::getTypeXMLElementName($type); $localProperties = $type->getLocalProperties()->getLocalPropertiesIterator(); -$properties = $type->getAllPropertiesIterator(); +$properties = $type->getAllPropertiesIndexedIterator(); ob_start(); diff --git a/template/versions/types/tests/integration/class.php b/template/versions/types/tests/integration/class.php index 423a5588..f46fe1e6 100644 --- a/template/versions/types/tests/integration/class.php +++ b/template/versions/types/tests/integration/class.php @@ -41,7 +41,7 @@ throw ExceptionUtils::createBundleTypeNotFoundException($type); } -foreach($bundleType->getAllPropertiesIterator() as $prop) { +foreach($bundleType->getAllPropertiesIndexedIterator() as $prop) { if ($prop->getName() === 'entry') { $bundleEntryProperty = $prop; break; diff --git a/template/versions/types/tests/validation/class.php b/template/versions/types/tests/validation/class.php index 7b4a0d83..3cb23de5 100644 --- a/template/versions/types/tests/validation/class.php +++ b/template/versions/types/tests/validation/class.php @@ -40,7 +40,7 @@ throw ExceptionUtils::createBundleTypeNotFoundException($type); } -foreach($bundleType->getAllPropertiesIterator() as $prop) { +foreach($bundleType->getAllPropertiesIndexedIterator() as $prop) { if ($prop->getName() === 'entry') { $bundleEntryProperty = $prop; break;