From 0c24ac361696d400fd5cec024248de0e9e5ca8c1 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Sun, 5 Jan 2025 17:49:33 -0600 Subject: [PATCH] lots of cleanup, some stupid bug somewhere --- files/constants.php | 36 +++--- src/Builder/Imports.php | 7 +- src/Builder/TypeBuilder.php | 32 +++--- src/Utilities/ExceptionUtils.php | 14 +++ src/Utilities/ImportUtils.php | 33 +++--- src/Version/Definition.php | 4 + src/Version/Definition/Properties.php | 28 ++++- src/Version/Definition/Type.php | 18 ++- src/Version/Definition/TypeDecorator.php | 8 ++ template/core/class_version_config.php | 24 ++-- template/core/client/class_client.php | 52 ++++----- template/core/client/class_config.php | 14 +-- template/core/client/class_request.php | 10 +- template/core/client/class_response.php | 8 +- .../core/client/class_response_headers.php | 2 +- template/core/client/enum_http_method.php | 2 +- template/core/client/enum_response_format.php | 2 +- template/core/client/enum_sort_direction.php | 2 +- .../core/client/exception_abstract_client.php | 6 +- .../core/client/exception_client_error.php | 2 +- .../exception_unexpected_response_code.php | 2 +- template/core/client/interface_client.php | 8 +- .../core/encoding/class_serialize_config.php | 4 +- .../encoding/class_unserialize_config.php | 4 +- template/core/encoding/class_xml_writer.php | 6 +- .../encoding/enum_serialize_config_key.php | 2 +- .../encoding/enum_unserialize_config_key.php | 2 +- template/core/encoding/enum_xml_location.php | 2 +- template/core/interface_comment_container.php | 6 +- template/core/interface_type.php | 16 +-- template/core/interface_version_config.php | 12 +- template/core/validation/class_validator.php | 2 +- template/versions/core/class_version.php | 2 +- .../core/class_version_api_client.php | 40 +++---- template/versions/types/class_default.php | 108 ++++++++---------- template/versions/types/class_xhtml.php | 30 ++--- template/versions/types/header.php | 22 +++- template/versions/types/methods/common.php | 38 ------ .../versions/types/methods/constructor.php | 2 - .../default_property_setter_call.php | 1 - .../versions/types/methods/contained_type.php | 30 ----- .../versions/types/properties/declaration.php | 3 +- .../versions/types/properties/methods.php | 46 -------- .../types/properties/methods/default.php | 24 ++-- .../versions/types/serialization/json.php | 6 +- .../types/serialization/json/default.php | 3 +- .../types/serialization/json/primitive.php | 4 +- .../serialization/json/resource_container.php | 5 +- template/versions/types/serialization/xml.php | 21 +--- .../serialization/xml/serialize/body.php | 25 ++-- .../serialization/xml/serialize/header.php | 18 +-- .../xml/serialize/resource_container.php | 18 +-- .../serialization/xml/unserialize/body.php | 23 ++-- .../serialization/xml/unserialize/header.php | 14 +-- .../types/tests/integration/class.php | 20 ++-- .../versions/types/tests/validation/class.php | 12 +- .../versions/types/validation/methods.php | 8 +- 57 files changed, 398 insertions(+), 495 deletions(-) delete mode 100644 template/versions/types/methods/common.php delete mode 100644 template/versions/types/methods/contained_type.php delete mode 100644 template/versions/types/properties/methods.php diff --git a/files/constants.php b/files/constants.php index 2e5416db..a01cc2bd 100644 --- a/files/constants.php +++ b/files/constants.php @@ -80,11 +80,8 @@ const PHPFHIR_CLASSNAME_FACTORY_VERSION_CONFIG = 'FactoryVersionConfig'; const PHPFHIR_CLASSNAME_FACTORY = 'Factory'; const PHPFHIR_CLASSNAME_VERSION_CONFIG = 'VersionConfig'; -const PHPFHIR_CLASSNAME_UNSERIALIZE_CONFIG = 'UnserializeConfig'; -const PHPFHIR_CLASSNAME_SERIALIZE_CONFIG = 'SerializeConfig'; const PHPFHIR_CLASSNAME_RESPONSE_PARSER = 'ResponseParser'; const PHPFHIR_CLASSNAME_CONSTANTS = 'Constants'; -const PHPFHIR_CLASSNAME_XML_WRITER = 'XMLWriter'; const PHPFHIR_CLASSNAME_VALIDATOR = 'Validator'; // Core interface names @@ -104,26 +101,32 @@ const PHPFHIR_ENUM_FACTORY_VERSION_CONFIG_KEY = 'FactoryVersionConfigKey'; const PHPFHIR_ENUM_FACTORY_CONFIG_KEY = 'FactoryConfigKeyEnum'; const PHPFHIR_ENUM_VERSION_CONFIG_KEY = 'VersionConfigKeyEnum'; -const PHPFHIR_ENUM_UNSERIALIZE_CONFIG_KEY = 'UnserializeConfigKeyEnum'; -const PHPFHIR_ENUM_SERIALIZE_CONFIG_KEY = 'SerializeConfigKeyEnum'; const PHPFHIR_ENUM_VERSION = 'VersionEnum'; -const PHPFHIR_ENUM_XML_LOCATION = 'XMLLocationEnum'; // Core exceptions const PHPFHIR_EXCEPTION_CLIENT_ABSTRACT_CLIENT = 'AbstractClientException'; const PHPFHIR_EXCEPTION_CLIENT_ERROR = 'ClientErrorException'; const PHPFHIR_EXCEPTION_CLIENT_UNEXPECTED_RESPONSE_CODE = 'UnexpectedResponseCodeException'; +// Core encoding entities +const PHPFHIR_ENCODING_CLASSNAME_XML_WRITER = 'XMLWriter'; +const PHPFHIR_ENCODING_ENUM_XML_LOCATION = 'XMLLocationEnum'; +const PHPFHIR_ENCODING_ENUM_SERIALIZE_CONFIG_KEY = 'SerializeConfigKeyEnum'; +const PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG = 'SerializeConfig'; +const PHPFHIR_ENCODING_ENUM_UNSERIALIZE_CONFIG_KEY = 'UnserializeConfigKeyEnum'; +const PHPFHIR_ENCODING_CLASSNAME_UNSERIALIZE_CONFIG = 'UnserializeConfig'; + + // Core client entities -const PHPFHIR_INTERFACE_CLIENT_CLIENT = 'ClientInterface'; -const PHPFHIR_CLASSNAME_CLIENT_CLIENT = 'Client'; -const PHPFHIR_CLASSNAME_CLIENT_CONFIG = 'Config'; -const PHPFHIR_CLASSNAME_CLIENT_REQUEST = 'Request'; -const PHPFHIR_CLASSNAME_CLIENT_RESPONSE = 'Response'; -const PHPFHIR_CLASSNAME_CLIENT_RESPONSE_HEADERS = 'ResponseHeaders'; -const PHPFHIR_ENUM_CLIENT_HTTP_METHOD = 'HTTPMethodEnum'; -const PHPFHIR_ENUM_CLIENT_SORT = 'SortDirectionEnum'; -const PHPFHIR_ENUM_CLIENT_RESPONSE_FORMAT = 'ResponseFormatEnum'; +const PHPFHIR_CLIENT_INTERFACE_CLIENT = 'ClientInterface'; +const PHPFHIR_CLIENT_CLASSNAME_CLIENT = 'Client'; +const PHPFHIR_CLIENT_CLASSNAME_CONFIG = 'Config'; +const PHPFHIR_CLIENT_CLASSNAME_REQUEST = 'Request'; +const PHPFHIR_CLIENT_CLASSNAME_RESPONSE = 'Response'; +const PHPFHIR_CLIENT_CLASSNAME_RESPONSE_HEADERS = 'ResponseHeaders'; +const PHPFHIR_CLIENT_ENUM_HTTP_METHOD = 'HTTPMethodEnum'; +const PHPFHIR_CLIENT_ENUM_SORT_DIRECTION = 'SortDirectionEnum'; +const PHPFHIR_CLIENT_ENUM_RESPONSE_FORMAT = 'ResponseFormatEnum'; // Version class names const PHPFHIR_CLASSNAME_VERSION = 'Version'; @@ -153,9 +156,6 @@ // Static test type, namespace, and class values. const PHPFHIR_TESTS_NAMESPACE_BASE = 'Tests'; -const PHPFHIR_TESTS_NAMESPACE_UNIT = PHPFHIR_TESTS_NAMESPACE_BASE . '\\Unit'; -const PHPFHIR_TESTS_NAMESPACE_INTEGRATION = PHPFHIR_TESTS_NAMESPACE_BASE . '\\Integration'; -const PHPFHIR_TESTS_NAMESPACE_VALIDATION = PHPFHIR_TESTS_NAMESPACE_BASE . '\\Validation'; const PHPFHIR_TEST_CLASSNAME_CONSTANTS = PHPFHIR_CLASSNAME_CONSTANTS . 'Test'; const PHPFHIR_TEST_CLASSNAME_AUTOLOADER = PHPFHIR_CLASSNAME_AUTOLOADER . 'Test'; const PHPFHIR_TEST_CLASSNAME_TYPE_MAP = PHPFHIR_CLASSNAME_VERSION_TYPE_MAP . 'Test'; diff --git a/src/Builder/Imports.php b/src/Builder/Imports.php index fbdbc31c..387fc57a 100644 --- a/src/Builder/Imports.php +++ b/src/Builder/Imports.php @@ -19,6 +19,7 @@ */ use DCarbone\PHPFHIR\Config; +use DCarbone\PHPFHIR\Utilities\ExceptionUtils; use DCarbone\PHPFHIR\Version; use DCarbone\PHPFHIR\Version\Definition\Type; @@ -147,9 +148,9 @@ public function requiredImportCount(): int /** * @param \DCarbone\PHPFHIR\Version\Definition\Type $type - * @return \DCarbone\PHPFHIR\Builder\Import|null + * @return \DCarbone\PHPFHIR\Builder\Import */ - public function getImportByType(Type $type): ?Import + public function getImportByType(Type $type): Import { $fqn = $type->getFullyQualifiedClassName(false); foreach ($this->_imports as $import) { @@ -157,7 +158,7 @@ public function getImportByType(Type $type): ?Import return $import; } } - return null; + throw ExceptionUtils::createMissingExpectedImportException($type->getFullyQualifiedClassName(false)); } /** diff --git a/src/Builder/TypeBuilder.php b/src/Builder/TypeBuilder.php index 082a9156..b8dbd969 100644 --- a/src/Builder/TypeBuilder.php +++ b/src/Builder/TypeBuilder.php @@ -34,13 +34,12 @@ abstract class TypeBuilder * @param string $sourceFilename * @return \DCarbone\PHPFHIR\Version\Definition\Type */ - private static function buildDefaultType( - Config $config, - Version $version, - string $fhirName, - SimpleXMLElement $sxe, - string $sourceFilename - ): Type { + private static function buildDefaultType(Config $config, + Version $version, + string $fhirName, + SimpleXMLElement $sxe, + string $sourceFilename): Type + { return new Type($config, $version, $fhirName, $sxe, $sourceFilename); } @@ -52,13 +51,12 @@ private static function buildDefaultType( * @param string $sourceFilename * @return \DCarbone\PHPFHIR\Version\Definition\Type */ - private static function buildPrimitiveType( - Config $config, - Version $version, - string $fhirName, - SimpleXMLElement $sxe, - string $sourceFilename - ): Type { + private static function buildPrimitiveType(Config $config, + Version $version, + string $fhirName, + SimpleXMLElement $sxe, + string $sourceFilename): Type + { $type = self::buildDefaultType($config, $version, $fhirName, $sxe, $sourceFilename); $value = new Property($type, $sxe, $sourceFilename); $value->setName(PHPFHIR_VALUE_PROPERTY_NAME); @@ -74,7 +72,11 @@ private static function buildPrimitiveType( * @param string $sourceFilename * @return \DCarbone\PHPFHIR\Version\Definition\Type */ - public static function build(Config $config, Version $version, string $fhirName, SimpleXMLElement $sxe, string $sourceFilename): Type + public static function build(Config $config, + Version $version, + string $fhirName, + SimpleXMLElement $sxe, + string $sourceFilename): Type { if (str_contains($fhirName, PHPFHIR_PRIMITIVE_SUFFIX) || str_contains($fhirName, PHPFHIR_LIST_SUFFIX)) { return self::buildPrimitiveType($config, $version, $fhirName, $sxe, $sourceFilename); diff --git a/src/Utilities/ExceptionUtils.php b/src/Utilities/ExceptionUtils.php index b2851e0a..36c22be1 100644 --- a/src/Utilities/ExceptionUtils.php +++ b/src/Utilities/ExceptionUtils.php @@ -512,4 +512,18 @@ public static function createBundleEntryPropertyNotFoundException(Type $type): \ ) ); } + + /** + * @param string $expectedImport + * @return \DomainException + */ + public static function createMissingExpectedImportException(string $expectedImport): \DomainException + { + return new \DomainException( + sprintf( + 'Missing expected import: %s', + $expectedImport, + ) + ); + } } \ No newline at end of file diff --git a/src/Utilities/ImportUtils.php b/src/Utilities/ImportUtils.php index 773d4a2b..3abe755e 100644 --- a/src/Utilities/ImportUtils.php +++ b/src/Utilities/ImportUtils.php @@ -41,6 +41,7 @@ public static function compileImportStatements(Imports $imports): string public static function buildVersionTypeImports(Type $type): void { $imports = $type->getImports(); + // immediately add self $imports->addImport($type->getFullyQualifiedNamespace(false), $type->getClassName()); @@ -49,17 +50,15 @@ public static function buildVersionTypeImports(Type $type): void $typeKind = $type->getKind(); - $allProperties = $type->getAllPropertiesIndexedIterator(); - if (!$type->isAbstract()) { - $imports->addCoreFileImportsByName(PHPFHIR_CLASSNAME_XML_WRITER); - $imports->addCoreFileImportsByName(PHPFHIR_ENUM_XML_LOCATION); + $imports->addCoreFileImportsByName(PHPFHIR_ENCODING_CLASSNAME_XML_WRITER); + $imports->addCoreFileImportsByName(PHPFHIR_ENCODING_ENUM_XML_LOCATION); } $imports->addVersionCoreFileImportsByName($type->getVersion(), PHPFHIR_CLASSNAME_VERSION); $imports->addVersionCoreFileImportsByName($type->getVersion(), PHPFHIR_CLASSNAME_VERSION_CONSTANTS); - $imports->addCoreFileImportsByName(PHPFHIR_CLASSNAME_UNSERIALIZE_CONFIG); - $imports->addCoreFileImportsByName(PHPFHIR_CLASSNAME_SERIALIZE_CONFIG); + $imports->addCoreFileImportsByName(PHPFHIR_ENCODING_CLASSNAME_UNSERIALIZE_CONFIG); + $imports->addCoreFileImportsByName(PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG); $imports->addCoreFileImportsByName(PHPFHIR_INTERFACE_TYPE); @@ -78,8 +77,10 @@ public static function buildVersionTypeImports(Type $type): void } if ($parentType = $type->getParentType()) { - $pns = $parentType->getFullyQualifiedNamespace(false); - $imports->addImport($pns, $parentType->getClassName()); + $imports->addImport( + $parentType->getFullyQualifiedNamespace(false), + $parentType->getClassName(), + ); } if ($type->hasLocalPropertiesWithValidations()) { @@ -87,11 +88,13 @@ public static function buildVersionTypeImports(Type $type): void } if ($restrictionBaseType = $type->getRestrictionBaseFHIRType()) { - $rns = $restrictionBaseType->getFullyQualifiedNamespace(false); - $imports->addImport($rns, $restrictionBaseType->getClassName()); + $imports->addImport( + $restrictionBaseType->getFullyQualifiedNamespace(false), + $restrictionBaseType->getClassName(), + ); } - foreach ($allProperties as $property) { + foreach ($type->getAllPropertiesIndexedIterator() as $property) { $propertyType = $property->getValueFHIRType(); if (null === $propertyType) { continue; @@ -111,12 +114,14 @@ public static function buildVersionTypeImports(Type $type): void $imports->addVersionCoreFileImportsByName($type->getVersion(), PHPFHIR_CLASSNAME_VERSION); } else { if ($ptk === TypeKindEnum::PRIMITIVE_CONTAINER) { - $primType = $propertyType->getLocalProperties()->getProperty('value')->getValueFHIRType(); + $primType = $propertyType->getLocalProperties()->getProperty(PHPFHIR_VALUE_PROPERTY_NAME)->getValueFHIRType(); $imports->addImport($primType->getFullyQualifiedNamespace(false), $primType->getClassName()); } - $propertyTypeNS = $propertyType->getFullyQualifiedNamespace(false); - $imports->addImport($propertyTypeNS, $propertyType->getClassName()); + $imports->addImport( + $propertyType->getFullyQualifiedNamespace(false), + $propertyType->getClassName(), + ); } } } diff --git a/src/Version/Definition.php b/src/Version/Definition.php index aa5167a6..43152d42 100644 --- a/src/Version/Definition.php +++ b/src/Version/Definition.php @@ -20,6 +20,7 @@ use DCarbone\PHPFHIR\Builder; use DCarbone\PHPFHIR\Config; +use DCarbone\PHPFHIR\Utilities\ImportUtils; use DCarbone\PHPFHIR\Version; use DCarbone\PHPFHIR\Version\Definition\TypeDecorationValidator; use DCarbone\PHPFHIR\Version\Definition\TypeDecorator; @@ -119,6 +120,9 @@ public function buildDefinition(): void $log->info('Setting comment container flags'); TypeDecorator::setCommentContainerFlag($this->config, $this->types); + $log->info('Compiling type imports'); + TypeDecorator::buildTypeImports($this->config, $this->types); + $log->info('Performing some sanity checking'); TypeDecorationValidator::validateDecoration($this->config, $this->version, $this->types); diff --git a/src/Version/Definition/Properties.php b/src/Version/Definition/Properties.php index 546c0c17..653e4d91 100644 --- a/src/Version/Definition/Properties.php +++ b/src/Version/Definition/Properties.php @@ -22,8 +22,6 @@ use DCarbone\PHPFHIR\Config; use DCarbone\PHPFHIR\Enum\TypeKindEnum; use DCarbone\PHPFHIR\Version; -use InvalidArgumentException; -use SplFixedArray; /** * Class Properties @@ -90,7 +88,7 @@ public function addProperty(Property &$property): Properties $pname = $property->getName(); $pref = $property->getRef(); if (null === $pname && null === $pref) { - throw new InvalidArgumentException( + throw new \InvalidArgumentException( sprintf( 'Cannot add Property to Type "%s" as it has no $name or $ref defined', $this->getType()->getFHIRName() @@ -175,7 +173,18 @@ public function getAllSortedPropertiesIterator(): iterable } /** - * Returns an iterator containing only properties local to this type + * Returns an indexed iterator containing only properties local to this type. + * + * @return \DCarbone\PHPFHIR\Version\Definition\Property[] + */ + public function getIndexedLocalPropertiesIterator(): iterable + { + $this->_buildLocalCaches(); + return \SplFixedArray::fromArray($this->_localProperties, preserveKeys: false); + } + + /** + * Returns an iterator containing only properties local to this type. * * @return \DCarbone\PHPFHIR\Version\Definition\Property[] */ @@ -185,6 +194,17 @@ public function getLocalPropertiesIterator(): iterable return new \ArrayIterator($this->_localProperties); } + /** + * @return \Generator<\DCarbone\PHPFHIR\Version\Definition\Property> + */ + public function getLocalPropertiesGenerator(): \Generator + { + $this->_buildLocalCaches(); + foreach($this->_localProperties as $p) { + yield $p; + } + } + /** * Returns an iterator containing only properties local to this type, sorted ascending by name * diff --git a/src/Version/Definition/Type.php b/src/Version/Definition/Type.php index a8b73b3e..a4ee3a7b 100644 --- a/src/Version/Definition/Type.php +++ b/src/Version/Definition/Type.php @@ -128,11 +128,6 @@ public function __construct( $this->sourceFilename = $sourceFilename; $this->localProperties = new Properties($config, $version, $this); $this->enumeration = new Enumeration(); - $this->imports = new Imports( - $config, - $this->getFullyQualifiedNamespace(false), - $this->getClassName(), - ); } /** @@ -174,6 +169,14 @@ public function getFHIRName(): string */ public function getImports(): Imports { + // TODO: implement "extraction done" mechanic + if (!isset($this->imports)) { + $this->imports = new Imports( + $this->config, + $this->getFullyQualifiedNamespace(false), + $this->getClassName(), + ); + } return $this->imports; } @@ -298,11 +301,6 @@ public function getFullyQualifiedNamespace(bool $leadingSlash): string return $this->getVersion()->getFullyQualifiedName($leadingSlash, $this->getTypeNamespace()); } - public function get() - { - - } - /** * @param \DCarbone\PHPFHIR\Enum\TestTypeEnum $testType * @param bool $leadingSlash diff --git a/src/Version/Definition/TypeDecorator.php b/src/Version/Definition/TypeDecorator.php index 9e28164b..01a9319a 100644 --- a/src/Version/Definition/TypeDecorator.php +++ b/src/Version/Definition/TypeDecorator.php @@ -22,6 +22,7 @@ use DCarbone\PHPFHIR\Enum\PrimitiveTypeEnum; use DCarbone\PHPFHIR\Enum\TypeKindEnum; use DCarbone\PHPFHIR\Utilities\ExceptionUtils; +use DCarbone\PHPFHIR\Utilities\ImportUtils; use DCarbone\PHPFHIR\Version; /** @@ -460,4 +461,11 @@ public static function parseUnionMemberTypes(Config $config, Types $types): void } } } + + public static function buildTypeImports(Config $config, Types $types): void + { + foreach ($types->getGenerator() as $type) { + ImportUtils::buildVersionTypeImports($type); + } + } } \ No newline at end of file diff --git a/template/core/class_version_config.php b/template/core/class_version_config.php index 872b646d..e799cbd1 100644 --- a/template/core/class_version_config.php +++ b/template/core/class_version_config.php @@ -23,14 +23,14 @@ $imports = $coreFile->getImports(); $imports->addCoreFileImportsByName( - PHPFHIR_CLASSNAME_SERIALIZE_CONFIG, - PHPFHIR_CLASSNAME_UNSERIALIZE_CONFIG, + PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG, + PHPFHIR_ENCODING_CLASSNAME_UNSERIALIZE_CONFIG, ); $coreFiles = $config->getCoreFiles(); -$serializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_SERIALIZE_CONFIG); -$unserializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_UNSERIALIZE_CONFIG); +$serializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG); +$unserializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_CLASSNAME_UNSERIALIZE_CONFIG); ob_start(); echo 'declare(strict_types=1); @@ -57,10 +57,10 @@ class implements getFullyQualifiedName(true); ?> */ - private $unserializeConfig; + private $unserializeConfig; /** @var getFullyQualifiedName(true); ?> */ - private $serializeConfig; + private $serializeConfig; /** * constructor. @@ -86,10 +86,10 @@ public function __construct(array $config = []) * @param array|getFullyQualifiedName(true); ?> $config * @return self */ - public function setUnserializeConfig(array| $config): self + public function setUnserializeConfig(array| $config): self { if (is_array($config)) { - $config = new ($config); + $config = new ($config); } $this->unserializeConfig = $config; return $this; @@ -99,7 +99,7 @@ public function setUnserializeConfig(array|getFullyQualifiedName(true); ?> */ - public function getUnserializeConfig(): + public function getUnserializeConfig(): { return $this->unserializeConfig; @@ -109,10 +109,10 @@ public function getUnserializeConfig(): getFullyQualifiedName(true); ?> $config * @return self */ - public function setSerializeConfig(array| $config): self + public function setSerializeConfig(array| $config): self { if (is_array($config)) { - $config = new ($config); + $config = new ($config); } $this->serializeConfig = $config; return $this; @@ -122,7 +122,7 @@ public function setSerializeConfig(array|getFullyQualifiedName(true); ?> */ - public function getSerializeConfig(): + public function getSerializeConfig(): { return $this->serializeConfig; diff --git a/template/core/client/class_client.php b/template/core/client/class_client.php index 04f2500b..0ee9abaa 100644 --- a/template/core/client/class_client.php +++ b/template/core/client/class_client.php @@ -25,16 +25,16 @@ $imports = $coreFile->getImports(); $imports->addCoreFileImportsByName( - PHPFHIR_CLASSNAME_CLIENT_CONFIG, - PHPFHIR_CLASSNAME_CLIENT_REQUEST, - PHPFHIR_CLASSNAME_CLIENT_RESPONSE, - PHPFHIR_ENUM_CLIENT_HTTP_METHOD, + PHPFHIR_CLIENT_CLASSNAME_CONFIG, + PHPFHIR_CLIENT_CLASSNAME_REQUEST, + PHPFHIR_CLIENT_CLASSNAME_RESPONSE, + PHPFHIR_CLIENT_ENUM_HTTP_METHOD, ); -$confClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_CLIENT_CONFIG); -$reqClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_CLIENT_REQUEST); -$respClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_CLIENT_RESPONSE); -$htMethodEnum = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENUM_CLIENT_HTTP_METHOD); +$confClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_CLASSNAME_CONFIG); +$reqClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_CLASSNAME_REQUEST); +$respClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_CLASSNAME_RESPONSE); +$htMethodEnum = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_ENUM_HTTP_METHOD); ob_start(); echo 'declare(strict_types=1); @@ -47,12 +47,12 @@ /** - * Class + * Class * - * Basic implementation of the interface. + * Basic implementation of the interface. */ -class implements +class implements { private const _PARAM_FORMAT = '_format'; @@ -65,22 +65,22 @@ class implements 'php-fhir client (build: getStandardDate(); ?>;)', ]; - protected $_config; + protected $_config; /** - * Constructor + * Constructor * * @param string|getFullyQualifiedName(true); ?> $config Fully qualified address of FHIR server, or configuration object. */ - public function __construct(string| $config) + public function __construct(string| $config) { if (is_string($config)) { - $config = new ($config); + $config = new ($config); } $this->_config = $config; } - public function getConfig(): + public function getConfig(): { return $this->_config; @@ -91,7 +91,7 @@ public function getConfig(): * @return getFullyQualifiedName(true); ?> */ - public function exec( $request): + public function exec( $request): { $queryParams = array_merge($this->_config->getQueryParams(), $request->queryParams ?? []); @@ -107,7 +107,7 @@ public function exec( $request): $queryParams[self::_PARAM_COUNT] = $request->count; } - $rc = new (); + $rc = new (); $url = "{$this->_config->getAddress()}{$request->path}?" . http_build_query($queryParams, '', '&', PHP_QUERY_RFC3986); @@ -157,10 +157,10 @@ public function exec( $request): return $rc; } - private function _exec(string|getEntityName(); ?> $method, string $path, array $queryParams = [], array $curlOpts = []): + private function _exec(string|getEntityName(); ?> $method, string $path, array $queryParams = [], array $curlOpts = []): { - $req = new (); + $req = new (); $req->method = (string)$method; $req->path = $path; $req->queryParams = $queryParams; @@ -168,37 +168,37 @@ private function _exec(string|getEntityName(); ?> $met return $this->exec($req); } - public function get(string $path, array $queryParams = [], array $curlOpts = []): + public function get(string $path, array $queryParams = [], array $curlOpts = []): { return $this->_exec(getEntityName(); ?>::GET, $path, $queryParams, $curlOpts); } - public function put(string $path, array $queryParams = [], array $curlOpts = []): + public function put(string $path, array $queryParams = [], array $curlOpts = []): { return $this->_exec(getEntityName(); ?>::PUT, $path, $queryParams, $curlOpts); } - public function post(string $path, array $queryParams = [], array $curlOpts = []): + public function post(string $path, array $queryParams = [], array $curlOpts = []): { return $this->_exec(getEntityName(); ?>::POST, $path, $queryParams, $curlOpts); } - public function patch(string $path, array $queryParams = [], array $curlOpts = []): + public function patch(string $path, array $queryParams = [], array $curlOpts = []): { return $this->_exec(getEntityName(); ?>::PATCH, $path, $queryParams, $curlOpts); } - public function delete(string $path, array $queryParams = [], array $curlOpts = []): + public function delete(string $path, array $queryParams = [], array $curlOpts = []): { return $this->_exec(getEntityName(); ?>::DELETE, $path, $queryParams, $curlOpts); } - public function head(string $path, array $queryParams = [], array $curlOpts = []): + public function head(string $path, array $queryParams = [], array $curlOpts = []): { return $this->_exec(getEntityName(); ?>::HEAD, $path, $queryParams, $curlOpts); diff --git a/template/core/client/class_config.php b/template/core/client/class_config.php index 7d7f0d80..a4cb9e91 100644 --- a/template/core/client/class_config.php +++ b/template/core/client/class_config.php @@ -21,7 +21,7 @@ $coreFiles = $config->getCoreFiles(); -$formatEnum = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENUM_CLIENT_RESPONSE_FORMAT); +$formatEnum = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_ENUM_RESPONSE_FORMAT); ob_start(); echo 'declare(strict_types=1); @@ -32,13 +32,13 @@ /** - * Class + * Class * * Configuration class for built-in FHIR API client. If you are not using the built-in client, * you can ignore this class. */ -class +class { /** @var string */ @@ -48,12 +48,12 @@ class /** @var array */ private array $_queryParams; /** @var null|getFullyQualifiedName(true); ?> */ - private null| $_defaultFormat; + private null| $_defaultFormat; /** @var bool */ private bool $_parseHeaders; /** - * Constructor + * Constructor * * @param string $address Fully qualified address of FHIR server, including scheme, port, and any path prefix. * @param array $curlOpts Base curl options array. These will be added to every request. May be overridden by an individual request. @@ -64,7 +64,7 @@ class public function __construct(string $address, array $curlOpts = [], array $queryParams = [], - null| $defaultFormat = null, + null| $defaultFormat = null, bool $parseHeaders = false) { $this->_address = $address; @@ -102,7 +102,7 @@ public function getQueryParams(): array * @return null|getFullyQualifiedName(true); ?> */ - public function getDefaultFormat(): null| + public function getDefaultFormat(): null| { return $this->_defaultFormat; diff --git a/template/core/client/class_request.php b/template/core/client/class_request.php index 3e072fd4..0693f41a 100644 --- a/template/core/client/class_request.php +++ b/template/core/client/class_request.php @@ -21,8 +21,8 @@ $coreFiles = $config->getCoreFiles(); -$formatEnum = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENUM_CLIENT_RESPONSE_FORMAT); -$sortEnum = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENUM_CLIENT_SORT); +$formatEnum = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_ENUM_RESPONSE_FORMAT); +$sortEnum = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_ENUM_SORT_DIRECTION); ob_start(); echo 'declare(strict_types=1); @@ -32,7 +32,7 @@ getBasePHPFHIRCopyrightComment(false); ?> -class +class { /** @var string */ @@ -52,10 +52,10 @@ class public bool $parseHeaders; /** @var getFullyQualifiedName(true); ?> */ - public $format; + public $format; /** @var getFullyQualifiedName(true); ?> */ - public $sort; + public $sort; /** * Extra query parameters. diff --git a/template/core/client/class_response.php b/template/core/client/class_response.php index 15368d39..8eab828c 100644 --- a/template/core/client/class_response.php +++ b/template/core/client/class_response.php @@ -21,7 +21,7 @@ $coreFiles = $config->getCoreFiles(); -$respHeaderClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_CLIENT_RESPONSE_HEADERS); +$respHeaderClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_CLASSNAME_RESPONSE_HEADERS); ob_start(); echo 'declare(strict_types=1); @@ -31,7 +31,7 @@ getBasePHPFHIRCopyrightComment(false); ?> -class +class { /** @@ -61,7 +61,7 @@ class * @var getFullyQualifiedName(true); ?> */ - public $headers; + public $headers; /** * HTTP response body. @@ -99,7 +99,7 @@ public function getCode(): null|int return $this->code ?? null; } - public function getHeaders(): null| + public function getHeaders(): null| { return $this->headers ?? null; diff --git a/template/core/client/class_response_headers.php b/template/core/client/class_response_headers.php index 8eb9926c..a4bd5f37 100644 --- a/template/core/client/class_response_headers.php +++ b/template/core/client/class_response_headers.php @@ -27,7 +27,7 @@ getBasePHPFHIRCopyrightComment(false); ?> -class implements \Countable +class implements \Countable { /** @var array */ private array $_headerLines = []; diff --git a/template/core/client/enum_http_method.php b/template/core/client/enum_http_method.php index 16367389..50f126e2 100644 --- a/template/core/client/enum_http_method.php +++ b/template/core/client/enum_http_method.php @@ -27,7 +27,7 @@ getBasePHPFHIRCopyrightComment(false); ?> -enum : string +enum : string { case GET = 'GET'; case PUT = 'PUT'; diff --git a/template/core/client/enum_response_format.php b/template/core/client/enum_response_format.php index bf59a0af..59779eba 100644 --- a/template/core/client/enum_response_format.php +++ b/template/core/client/enum_response_format.php @@ -27,7 +27,7 @@ getBasePHPFHIRCopyrightComment(false); ?> -enum : string +enum : string { case XML = 'xml'; case JSON = 'json'; diff --git a/template/core/client/enum_sort_direction.php b/template/core/client/enum_sort_direction.php index 82f5e2c4..ea16c862 100644 --- a/template/core/client/enum_sort_direction.php +++ b/template/core/client/enum_sort_direction.php @@ -27,7 +27,7 @@ getBasePHPFHIRCopyrightComment(false); ?> -enum : string +enum : string { case LAST_UPDATED_DESC = '-_lastUpdated'; case LAST_UPDATED_ASC = '_lastUpdated'; diff --git a/template/core/client/exception_abstract_client.php b/template/core/client/exception_abstract_client.php index a161c640..1d07158c 100644 --- a/template/core/client/exception_abstract_client.php +++ b/template/core/client/exception_abstract_client.php @@ -21,7 +21,7 @@ $coreFiles = $config->getCoreFiles(); -$respClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_CLIENT_RESPONSE); +$respClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_CLASSNAME_RESPONSE); ob_start(); echo 'declare(strict_types=1); @@ -33,13 +33,13 @@ abstract class extends \Exception { /** @var getFullyQualifiedName(true); ?> */ - protected $_rc; + protected $_rc; /** * @return getFullyQualifiedName(true); ?> */ - public function getResponse(): + public function getResponse(): { return $this->_rc; diff --git a/template/core/client/exception_client_error.php b/template/core/client/exception_client_error.php index 283e2ee8..36e7a67a 100644 --- a/template/core/client/exception_client_error.php +++ b/template/core/client/exception_client_error.php @@ -30,7 +30,7 @@ class extends { - public function __construct( $rc) { + public function __construct( $rc) { parent::__construct($rc->err, $rc->errno); $this->_rc = $rc; } diff --git a/template/core/client/exception_unexpected_response_code.php b/template/core/client/exception_unexpected_response_code.php index afd282b8..4d499195 100644 --- a/template/core/client/exception_unexpected_response_code.php +++ b/template/core/client/exception_unexpected_response_code.php @@ -33,7 +33,7 @@ class extends < /** @var int */ private int $_expectedCode; - public function __construct( $rc, int $expectedCode) { + public function __construct( $rc, int $expectedCode) { parent::__construct(sprintf('Response returned code %d, expected %d', $rc->errno, $expectedCode)); $this->_rc = $rc; $this->_expectedCode = $expectedCode; diff --git a/template/core/client/interface_client.php b/template/core/client/interface_client.php index 790d892e..e60043b5 100644 --- a/template/core/client/interface_client.php +++ b/template/core/client/interface_client.php @@ -21,8 +21,8 @@ $coreFiles = $config->getCoreFiles(); -$reqClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_CLIENT_REQUEST); -$respClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_CLIENT_RESPONSE); +$reqClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_CLASSNAME_REQUEST); +$respClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_CLASSNAME_RESPONSE); ob_start(); echo 'declare(strict_types=1); @@ -32,7 +32,7 @@ getBasePHPFHIRCopyrightComment(false); ?> -interface +interface { /** @@ -42,6 +42,6 @@ interface * @return getFullyQualifiedName(true); ?> */ - public function exec( $request): ; + public function exec( $request): ; } getBasePHPFHIRCopyrightComment(false); ?> -class +class { /** @var bool */ @@ -39,7 +39,7 @@ class public function __construct(array $config) { - foreach(::cases() as $k) { + foreach(::cases() as $k) { if (isset($config[$k->value]) || array_key_exists($k->value, $config)) { $this->{"set{$k->value}"}($config[$k->value]); } diff --git a/template/core/encoding/class_unserialize_config.php b/template/core/encoding/class_unserialize_config.php index 081465ea..8f54a099 100644 --- a/template/core/encoding/class_unserialize_config.php +++ b/template/core/encoding/class_unserialize_config.php @@ -27,7 +27,7 @@ getBasePHPFHIRCopyrightComment(false); ?> -class +class { /** @var int */ @@ -37,7 +37,7 @@ class public function __construct(array $config) { - foreach(::cases() as $k) { + foreach(::cases() as $k) { if (isset($config[$k->value]) || array_key_exists($k->value, $config)) { $this->{"set{$k->value}"}($config[$k->value]); } diff --git a/template/core/encoding/class_xml_writer.php b/template/core/encoding/class_xml_writer.php index d7edf586..bfb9b7e8 100644 --- a/template/core/encoding/class_xml_writer.php +++ b/template/core/encoding/class_xml_writer.php @@ -21,7 +21,7 @@ $coreFiles = $config->getCoreFiles(); -$serializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_SERIALIZE_CONFIG); +$serializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG); ob_start(); echo 'declare(strict_types=1); @@ -37,7 +37,7 @@ * This class is intended specifically for internal use within the PHPFHIR library. Use outside this scope is not * promoted or supported. */ -final class extends \XMLWriter +final class extends \XMLWriter { private const _MEM = 'memory'; @@ -165,7 +165,7 @@ public function isRootOpen(): bool * @param string|null $sourceXMLNS * @return bool */ - public function openRootNode( $config, string $name, null|string $sourceXMLNS): bool + public function openRootNode( $config, string $name, null|string $sourceXMLNS): bool { if (null === $this->_open) { throw new \LogicException('Must open write destination before writing root node'); diff --git a/template/core/encoding/enum_serialize_config_key.php b/template/core/encoding/enum_serialize_config_key.php index 8f6204c6..d364f0b8 100644 --- a/template/core/encoding/enum_serialize_config_key.php +++ b/template/core/encoding/enum_serialize_config_key.php @@ -27,7 +27,7 @@ getBasePHPFHIRCopyrightComment(false); ?> -enum : string +enum : string { case OVERRIDE_SOURCE_XMLNS = 'overrideSourceXMLNS'; case ROOT_XMLNS = 'rootXMLNS'; diff --git a/template/core/encoding/enum_unserialize_config_key.php b/template/core/encoding/enum_unserialize_config_key.php index 7db46e7a..bc7e2b12 100644 --- a/template/core/encoding/enum_unserialize_config_key.php +++ b/template/core/encoding/enum_unserialize_config_key.php @@ -27,7 +27,7 @@ getBasePHPFHIRCopyrightComment(false); ?> -enum : string +enum : string { case LIBXML_OPTS = 'libxmlOpts'; case JSON_DECODE_MAX_DEPTH = 'jsonDecodeMaxDepth'; diff --git a/template/core/encoding/enum_xml_location.php b/template/core/encoding/enum_xml_location.php index a1180996..f8a32d9b 100644 --- a/template/core/encoding/enum_xml_location.php +++ b/template/core/encoding/enum_xml_location.php @@ -27,7 +27,7 @@ getBasePHPFHIRCopyrightComment(false); ?> -enum : string +enum : string { case ATTRIBUTE = 'attribute'; case ELEMENT = 'element'; diff --git a/template/core/interface_comment_container.php b/template/core/interface_comment_container.php index aa461c8d..66c4e24d 100644 --- a/template/core/interface_comment_container.php +++ b/template/core/interface_comment_container.php @@ -39,15 +39,13 @@ public function _getFHIRComments(): array; /** * Set internal fhir_comments list, overwriting any previous value(s) * @param array $fhirComments - * @return static */ - public function _setFHIRComments(array $fhirComments): self; + public function _setFHIRComments(array $fhirComments): void; /** * Append comment string to internal fhir_comments list * @param string $fhirComment - * @return static */ - public function _addFHIRComment(string $fhirComment): self; + public function _addFHIRComment(string $fhirComment): void; } getImports(); $imports->addCoreFileImportsByName( - PHPFHIR_CLASSNAME_SERIALIZE_CONFIG, - PHPFHIR_CLASSNAME_UNSERIALIZE_CONFIG, - PHPFHIR_CLASSNAME_XML_WRITER, + PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG, + PHPFHIR_ENCODING_CLASSNAME_UNSERIALIZE_CONFIG, + PHPFHIR_ENCODING_CLASSNAME_XML_WRITER, ); $coreFiles = $config->getCoreFiles(); -$serializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_SERIALIZE_CONFIG); -$unserializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_UNSERIALIZE_CONFIG); -$xmlWriterClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_XML_WRITER); +$serializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG); +$unserializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_CLASSNAME_UNSERIALIZE_CONFIG); +$xmlWriterClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_CLASSNAME_XML_WRITER); ob_start(); echo 'declare(strict_types=1); @@ -81,7 +81,7 @@ public function _getValidationErrors(): array; * @param null|getFullyQualifiedName(true); ?> $config * @return null|static */ - public static function xmlUnserialize(null|string|\SimpleXMLElement $element, null| $type = null, null| $config = null): null|self; + public static function xmlUnserialize(null|string|\SimpleXMLElement $element, null| $type = null, null| $config = null): null|self; /** * @param null|getFullyQualifiedName(true); ?> $xw @@ -89,7 +89,7 @@ public static function xmlUnserialize(null|string|\SimpleXMLElement $element, nu * @return getFullyQualifiedName(true); ?> */ - public function xmlSerialize(null| $xw = null, null| $config = null): ; + public function xmlSerialize(null| $xw = null, null| $config = null): ; /** * @return string diff --git a/template/core/interface_version_config.php b/template/core/interface_version_config.php index da0b6a9c..1db4a8f5 100644 --- a/template/core/interface_version_config.php +++ b/template/core/interface_version_config.php @@ -23,14 +23,14 @@ $imports = $coreFile->getImports(); $imports->addCoreFileImportsByName( - PHPFHIR_CLASSNAME_SERIALIZE_CONFIG, - PHPFHIR_CLASSNAME_UNSERIALIZE_CONFIG, + PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG, + PHPFHIR_ENCODING_CLASSNAME_UNSERIALIZE_CONFIG, ); $coreFiles = $config->getCoreFiles(); -$serializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_SERIALIZE_CONFIG); -$unserializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_UNSERIALIZE_CONFIG); +$serializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG); +$unserializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_CLASSNAME_UNSERIALIZE_CONFIG); ob_start(); echo 'declare(strict_types=1); @@ -50,12 +50,12 @@ interface * @return getFullyQualifiedName(true); ?> */ - public function getUnserializeConfig(): ; + public function getUnserializeConfig(): ; /** * Must return the serialization config to use for this version * @return getFullyQualifiedName(true); ?> */ - public function getSerializeConfig(): ; + public function getSerializeConfig(): ; } ::VALIDATE_ENUM => static::assertValueInEnum($typeName, $fieldName, $constraint, $value), diff --git a/template/versions/core/class_version.php b/template/versions/core/class_version.php index 74f9dc89..9f3b9a30 100644 --- a/template/versions/core/class_version.php +++ b/template/versions/core/class_version.php @@ -23,7 +23,7 @@ $coreFiles = $config->getCoreFiles(); $versionCoreFiles = $version->getCoreFiles(); -$clientInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_INTERFACE_CLIENT_CLIENT); +$clientInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_INTERFACE_CLIENT); $versionInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_INTERFACE_VERSION); $versionConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_VERSION_CONFIG); $versionConfigInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_INTERFACE_VERSION_CONFIG); diff --git a/template/versions/core/class_version_api_client.php b/template/versions/core/class_version_api_client.php index d4e8fd87..84e9744f 100644 --- a/template/versions/core/class_version_api_client.php +++ b/template/versions/core/class_version_api_client.php @@ -29,11 +29,11 @@ $imports = $coreFile->getImports(); $imports ->addCoreFileImportsByName( - PHPFHIR_INTERFACE_CLIENT_CLIENT, - PHPFHIR_ENUM_CLIENT_RESPONSE_FORMAT, - PHPFHIR_ENUM_CLIENT_SORT, - PHPFHIR_CLASSNAME_CLIENT_REQUEST, - PHPFHIR_CLASSNAME_CLIENT_RESPONSE, + PHPFHIR_CLIENT_INTERFACE_CLIENT, + PHPFHIR_CLIENT_ENUM_RESPONSE_FORMAT, + PHPFHIR_CLIENT_ENUM_SORT_DIRECTION, + PHPFHIR_CLIENT_CLASSNAME_REQUEST, + PHPFHIR_CLIENT_CLASSNAME_RESPONSE, PHPFHIR_EXCEPTION_CLIENT_ERROR, PHPFHIR_EXCEPTION_CLIENT_UNEXPECTED_RESPONSE_CODE, PHPFHIR_CLASSNAME_RESPONSE_PARSER, @@ -47,11 +47,11 @@ $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); +$clientInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_INTERFACE_CLIENT); +$clientResponseFormatEnum = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_ENUM_RESPONSE_FORMAT); +$clientSortEnum = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_ENUM_SORT_DIRECTION); +$clientRequestClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_CLASSNAME_REQUEST); +$clientResponseClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_CLASSNAME_RESPONSE); $clientErrorException = $coreFiles->getCoreFileByEntityName(PHPFHIR_EXCEPTION_CLIENT_ERROR); $clientUnexpectedResponseCodeException = $coreFiles->getCoreFileByEntityName(PHPFHIR_EXCEPTION_CLIENT_UNEXPECTED_RESPONSE_CODE); $responseParserClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_RESPONSE_PARSER); @@ -75,7 +75,7 @@ class { private const _STATUS_OK = 200; - protected $_client; + protected $_client; protected $_version; /** @@ -84,7 +84,7 @@ class * @param getFullyQualifiedName(true); ?> $client * @param getFullyQualifiedName(true, PHPFHIR_CLASSNAME_VERSION); ?> $version */ - public function __construct( $client, $version) + public function __construct( $client, $version) { $this->_client = $client; $this->_version = $version; @@ -109,17 +109,17 @@ public function __construct( $clie public function readRaw(string| $resourceType, null|string|getClassName(); ?>|getClassName(); ?> $resourceID = null, null|int $count = null, - null| $sort = null, - null| $format = null, + null| $sort = null, + null| $format = null, null|array $queryParams = null, - null|bool $parseHeaders = null): + null|bool $parseHeaders = null): { if (!is_string($resourceType)) { $resourceType = $resourceType->value; } - $req = new (); + $req = new (); $req->method = 'GET'; $req->path = "/{$resourceType}"; if (null !== $resourceID) { @@ -163,8 +163,8 @@ public function readRaw(string| $resourc public function read(string| $resourceType, null|string|getClassName(); ?>|getClassName(); ?> $resourceID = null, null|int $count = null, - null| $sort = null, - null| $format = null, + null| $sort = null, + null| $format = null, null|array $queryParams = null, null|bool $parseHeaders = null): null| @@ -181,7 +181,7 @@ public function read(string| $resourceTy * @throws getFullyQualifiedName(true); ?> */ - protected function _requireOK( $rc): void + protected function _requireOK( $rc): void { if (isset($rc->err)) { throw new ($rc); @@ -209,7 +209,7 @@ protected function _requireOK( $ * @throws \Exception */ public function readgetFHIRName(); ?>(string|getClassName(); ?>|getClassName(); ?> $resourceID, - null| $format = null): null| + null| $format = null): null| { $rc = $this->readRaw(resourceType: ::getConstName(false); ?>, diff --git a/template/versions/types/class_default.php b/template/versions/types/class_default.php index 010b5ab4..53eb9012 100644 --- a/template/versions/types/class_default.php +++ b/template/versions/types/class_default.php @@ -25,13 +25,7 @@ /** @var \DCarbone\PHPFHIR\Version\Definition\Type $type */ // define some common things -$typeClassName = $type->getClassName(); $typeKind = $type->getKind(); -$parentType = $type->getParentType(); -$localProperties = $type->getLocalProperties()->getLocalPropertiesIterator(); -$classDocumentation = $type->getDocBlockDocumentationFragment(1, true); -$interfaces = $type->getDirectlyImplementedInterfaces(); -$traits = $type->getDirectlyUsedTraits(); ob_start(); @@ -40,37 +34,18 @@ PHPFHIR_TEMPLATE_VERSION_TYPES_DIR . DIRECTORY_SEPARATOR . 'header.php', [ 'version' => $version, - 'skipImports' => false, 'type' => $type, - 'types' => $types, ] -); - -?> -/** - - - - */ -isAbstract()) : ?>abstract class getClassName(); ?> extends getClassName(); endif; ?> - implements - -{ - - use ; - +); ?> // name of FHIR type this class describes public const FHIR_TYPE_NAME = getTypeNameConst(true); ?>; hasLocalProperties()) : echo "\n"; - foreach ($localProperties as $property) : + foreach ($type->getLocalProperties()->getLocalPropertiesGenerator() as $property) : if ($property->getMemberOf()->hasPrimitiveParent()) { continue; } @@ -87,7 +62,7 @@ echo "\n"; // -- directly implemented properties - foreach ($localProperties as $property) : ?> + foreach ($type->getLocalProperties()->getLocalPropertiesGenerator() as $property) : ?> /** * @var @@ -104,7 +79,7 @@ getLocalProperties()->getLocalPropertiesGenerator() as $property) : $validationMap = $property->buildValidationMap(); if ([] !== $validationMap) : ?> @@ -136,44 +111,54 @@ [ 'version' => $version, 'type' => $type, - 'properties' => $localProperties, - 'parentType' => $parentType, ] ); ?> + /** + * @return string + */ + public function _getFHIRTypeName(): string + { + return self::FHIR_TYPE_NAME; + } + $version, - 'type' => $type, - 'parentType' => $type->getParentType(), - ] -); - -if ($type->isContainedType()) { - echo "\n"; +if ($type->isContainedType()) : ?> - echo require_with( - PHPFHIR_TEMPLATE_VERSION_TYPES_METHODS_DIR . DIRECTORY_SEPARATOR . 'contained_type.php', - [ - 'version' => $version, - 'type' => $type, - ] - ); -} + /** + * @return string + */ + public function _getResourceType(): string + { + return static::FHIR_TYPE_NAME; + } +hasLocalProperties()) { echo "\n"; - echo require_with( - PHPFHIR_TEMPLATE_VERSION_TYPES_PROPERTIES_DIR . DIRECTORY_SEPARATOR . 'methods.php', - [ - 'version' => $version, - 'type' => $type, - 'properties' => $localProperties, - ] - ); + // --- property methods + + if ($type->getKind()->isOneOf(TypeKindEnum::PRIMITIVE, TypeKindEnum::LIST)) : + echo require_with( + PHPFHIR_TEMPLATE_VERSION_TYPES_PROPERTIES_DIR . DIRECTORY_SEPARATOR . 'methods' . DIRECTORY_SEPARATOR . 'primitive.php', + [ + 'version' => $version, + 'type' => $type + ] + ); + else : + echo require_with( + PHPFHIR_TEMPLATE_VERSION_TYPES_PROPERTIES_DIR . DIRECTORY_SEPARATOR . 'methods' . DIRECTORY_SEPARATOR . 'default.php', + [ + 'version' => $version, + 'type' => $type, + ] + ); + endif; + + // --- end property methods echo "\n"; @@ -192,9 +177,6 @@ [ 'version' => $version, 'type' => $type, - 'typeKind' => $typeKind, - 'parentType' => $parentType, - 'typeClassName' => $typeClassName, ] ); diff --git a/template/versions/types/class_xhtml.php b/template/versions/types/class_xhtml.php index 9dfbc24a..688bddca 100644 --- a/template/versions/types/class_xhtml.php +++ b/template/versions/types/class_xhtml.php @@ -22,13 +22,19 @@ /** @var \DCarbone\PHPFHIR\Version\Definition\Types $types */ /** @var \DCarbone\PHPFHIR\Version\Definition\Type $type */ +$imports = $type->getImports(); + +$imports->addCoreFileImportsByName( + PHPFHIR_ENCODING_CLASSNAME_XML_WRITER, + PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG, +); + $config = $version->getConfig(); $coreFiles = $config->getCoreFiles(); -$xmlWriterClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_XML_WRITER); -$serializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLASSNAME_SERIALIZE_CONFIG); +$xmlWriterClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_CLASSNAME_XML_WRITER); +$serializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG); -$classDocumentation = $type->getDocBlockDocumentationFragment(1, true); $xmlName = NameUtils::getTypeXMLElementName($type); ob_start(); @@ -39,20 +45,8 @@ [ 'version' => $version, 'type' => $type, - 'types' => $types, ] -); - -// build class header ?> -/** - - - */ - -class getClassName(); ?> implements - -{ - use ; +); ?> /** @var null|string */ private null|string $_xhtml = null; @@ -184,11 +178,11 @@ public function getXMLReader(int $libxmlOpts): null|\XMLReader * @return getFullyQualifiedName(true); ?> */ - public function xmlSerialize(null| $xw = null, null| $config = null): + public function xmlSerialize(null| $xw = null, null| $config = null): { if (null === $xw) { - $xw = new (); + $xw = new (); } if (!$xw->isOpen()) { $xw->openMemory(); diff --git a/template/versions/types/header.php b/template/versions/types/header.php index 4a002477..557b912c 100644 --- a/template/versions/types/header.php +++ b/template/versions/types/header.php @@ -18,11 +18,14 @@ use DCarbone\PHPFHIR\Utilities\ImportUtils; -/** @var \DCarbone\PHPFHIR\Config $config */ /** @var \DCarbone\PHPFHIR\Version $version */ -/** @var \DCarbone\PHPFHIR\Version\Definition\Types $types */ /** @var \DCarbone\PHPFHIR\Version\Definition\Type $type */ +$parentType = $type->getParentType(); +$classDocumentation = $type->getDocBlockDocumentationFragment(1, true); +$interfaces = $type->getDirectlyImplementedInterfaces(); +$traits = $type->getDirectlyUsedTraits(); + ob_start(); echo ' declare(strict_types=1); @@ -32,10 +35,21 @@ getImports()); echo "\n"; +if ('' !== $classDocumentation) : ?>/** + + */ +isAbstract()) : ?>abstract class getClassName(); ?> extends getClassName(); endif; ?> + implements + +{ + + use ; + - /** - * @return string - */ - public function _getFHIRTypeName(): string - { - return self::FHIR_TYPE_NAME; - } - $version, - 'type' => $type, 'property' => $property, ] ); diff --git a/template/versions/types/methods/constructors/default_property_setter_call.php b/template/versions/types/methods/constructors/default_property_setter_call.php index 31bda444..a205362c 100644 --- a/template/versions/types/methods/constructors/default_property_setter_call.php +++ b/template/versions/types/methods/constructors/default_property_setter_call.php @@ -18,7 +18,6 @@ use DCarbone\PHPFHIR\Enum\TypeKindEnum; -/** @var \DCarbone\PHPFHIR\Version\Definition\Type $type */ /** @var \DCarbone\PHPFHIR\Version\Definition\Property $property */ $propertyType = $property->getValueFHIRType(); diff --git a/template/versions/types/methods/contained_type.php b/template/versions/types/methods/contained_type.php deleted file mode 100644 index 3eacd8b3..00000000 --- a/template/versions/types/methods/contained_type.php +++ /dev/null @@ -1,30 +0,0 @@ - - /** - * @return string - */ - public function _getResourceType(): string - { - return static::FHIR_TYPE_NAME; - } -isCollection(); $documentation = DocumentationUtils::compilePropertyDocumentation($property, 5, true); ob_start(); @@ -35,5 +34,5 @@ */ - protected $getName(); ?> = ; + protected $getName(); ?> = isCollection() ? '[]' : 'null'; ?>; getKind()->isOneOf(TypeKindEnum::PRIMITIVE, TypeKindEnum::LIST)) : - echo require_with( - PHPFHIR_TEMPLATE_VERSION_TYPES_PROPERTIES_DIR . DIRECTORY_SEPARATOR . 'methods' . DIRECTORY_SEPARATOR . 'primitive.php', - [ - 'version' => $version, - 'type' => $type - ] - ); -else : - echo require_with( - PHPFHIR_TEMPLATE_VERSION_TYPES_PROPERTIES_DIR . DIRECTORY_SEPARATOR . 'methods' . DIRECTORY_SEPARATOR . 'default.php', - [ - 'version' => $version, - 'type' => $type, - 'properties' => $properties, - ] - ); -endif; - -return ob_get_clean(); \ No newline at end of file diff --git a/template/versions/types/properties/methods/default.php b/template/versions/types/properties/methods/default.php index 29fb3c0e..e41b0ebf 100644 --- a/template/versions/types/properties/methods/default.php +++ b/template/versions/types/properties/methods/default.php @@ -20,16 +20,22 @@ use DCarbone\PHPFHIR\Utilities\DocumentationUtils; use DCarbone\PHPFHIR\Utilities\TypeHintUtils; -/** @var \DCarbone\PHPFHIR\Config $version */ /** @var \DCarbone\PHPFHIR\Version $version */ /** @var \DCarbone\PHPFHIR\Version\Definition\Type $type */ -/** @var \DCarbone\PHPFHIR\Version\Definition\Property[] $properties */ $config = $version->getConfig(); +$coreFiles = $config->getCoreFiles(); + +$xmlLocationEnum = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_ENUM_XML_LOCATION); + +$versionCoreFiles = $version->getCoreFiles(); + +$versionContainedTypeInterface = $versionCoreFiles->getCoreFileByEntityName(PHPFHIR_INTERFACE_VERSION_CONTAINED_TYPE); + $isPrimitiveType = $type->getKind()->isOneOf(TypeKindEnum::PRIMITIVE, TypeKindEnum::LIST); ob_start(); -foreach ($properties as $i => $property) : +foreach ($type->getLocalProperties()->getIndexedLocalPropertiesIterator() as $i => $property) : if ($property->isOverloaded()) { continue; } @@ -93,10 +99,10 @@ public function getGenerator(): \Generator * @param $ - * @param getFullyQualifiedName(true, PHPFHIR_ENUM_XML_LOCATION); ?> $xmlLocation + * @param getFullyQualifiedName(true); ?> $xmlLocation * @return static */ - public function getSetterName(); ?>( $ = null, $xmlLocation = ::isValueContainer()): ?>ELEMENTATTRIBUTE): self + public function getSetterName(); ?>( $ = null, $xmlLocation = ::isValueContainer()): ?>ELEMENTATTRIBUTE): self { if (null !== $ && !($ instanceof )) { $ = new ($); @@ -107,7 +113,7 @@ public function getSetterName(); ?>(if ([] === $this->_xmlLocations[self::getFieldConstantName(); ?>]) { $this->_xmlLocations[self::getFieldConstantName(); ?>][0] = $xmlLocation; } else { - $this->_xmlLocations[self::getFieldConstantName(); ?>][] = ::ELEMENT; + $this->_xmlLocations[self::getFieldConstantName(); ?>][] = ::ELEMENT; } $this->_xmlLocations[self::getFieldConstantName(); ?>][0] = $xmlLocation; @@ -124,10 +130,10 @@ public function getSetterName(); ?>(getFullyQualifiedClassName(true);?>[] $ - * @param getFullyQualifiedName(true, PHPFHIR_ENUM_XML_LOCATION); ?> $xmlLocation + * @param getFullyQualifiedName(true); ?> $xmlLocation * @return static */ - public function set(array $ = [], $xmlLocation = ::isValueContainer()): ?>ELEMENTATTRIBUTE): self + public function set(array $ = [], $xmlLocation = ::isValueContainer()): ?>ELEMENTATTRIBUTE): self { unset($this->_xmlLocations[self::getFieldConstantName(); ?>]); if ([] !== $this->) { @@ -171,7 +177,7 @@ public function getSetterName() ?>(null| * - * @param getFullyQualifiedName(true) . '\\' . PHPFHIR_INTERFACE_VERSION_CONTAINED_TYPE; ?>[] $ + * @param getFullyQualifiedName(true); ?>[] $ * @return static */ diff --git a/template/versions/types/serialization/json.php b/template/versions/types/serialization/json.php index bafcd0b5..9c45b2f8 100644 --- a/template/versions/types/serialization/json.php +++ b/template/versions/types/serialization/json.php @@ -31,15 +31,14 @@ [ 'version' => $version, 'type' => $type, - 'typeKind' => $typeKind, ] ); -elseif ($typeKind->isOneOf(TypeKindEnum::RESOURCE_CONTAINER, TypeKindEnum::RESOURCE_INLINE)) : +elseif ($typeKind->isContainer($version)) : echo require_with( PHPFHIR_TEMPLATE_VERSION_TYPES_SERIALIZATION_DIR . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR . 'resource_container.php', [ 'version' => $version, - 'properties' => $localProperties, + 'type' => $type, ] ); else: @@ -48,7 +47,6 @@ [ 'version' => $version, 'type' => $type, - 'properties' => $localProperties, ] ); endif; diff --git a/template/versions/types/serialization/json/default.php b/template/versions/types/serialization/json/default.php index b9af2582..f1556280 100644 --- a/template/versions/types/serialization/json/default.php +++ b/template/versions/types/serialization/json/default.php @@ -20,7 +20,6 @@ /** @var \DCarbone\PHPFHIR\Version $version */ /** @var \DCarbone\PHPFHIR\Version\Definition\Type $type */ -/** @var \DCarbone\PHPFHIR\Version\Definition\Property[] $properties */ ob_start(); ?> /** @@ -39,7 +38,7 @@ public function jsonSerialize(): mixed $out->{::JSON_FIELD_FHIR_COMMENTS} = $vs; } getLocalProperties()->getLocalPropertiesGenerator() as $property) : $propConst = $property->getFieldConstantName(); $propConstExt = $property->getFieldConstantExtensionName(); $getter = $property->getGetterName(); diff --git a/template/versions/types/serialization/json/primitive.php b/template/versions/types/serialization/json/primitive.php index 569ba1cc..354066e9 100644 --- a/template/versions/types/serialization/json/primitive.php +++ b/template/versions/types/serialization/json/primitive.php @@ -19,10 +19,10 @@ use DCarbone\PHPFHIR\Enum\TypeKindEnum; use DCarbone\PHPFHIR\Utilities\TypeHintUtils; -/** @var \DCarbone\PHPFHIR\Config $config */ /** @var \DCarbone\PHPFHIR\Version $version */ /** @var \DCarbone\PHPFHIR\Version\Definition\Type $type */ -/** @var \DCarbone\PHPFHIR\Enum\TypeKindEnum $typeKind */ + +$typeKind = $type->getKind(); ob_start(); ?> /** diff --git a/template/versions/types/serialization/json/resource_container.php b/template/versions/types/serialization/json/resource_container.php index b7d19cdd..b425b696 100644 --- a/template/versions/types/serialization/json/resource_container.php +++ b/template/versions/types/serialization/json/resource_container.php @@ -16,14 +16,15 @@ * limitations under the License. */ -/** @var \DCarbone\PHPFHIR\Version\Definition\Property[] $properties */ +/** @var \DCarbone\PHPFHIR\Version $version */ +/** @var \DCarbone\PHPFHIR\Version\Definition\Type $type */ ob_start(); ?> /** * @return null|object */ public function jsonSerialize(): mixed - { + {getLocalProperties()->getLocalPropertiesGenerator() as $property) : ?> if (null !== ($v = $this->getgetName()); ?>())) { return $v; diff --git a/template/versions/types/serialization/xml.php b/template/versions/types/serialization/xml.php index 27fb7ea0..fec83514 100644 --- a/template/versions/types/serialization/xml.php +++ b/template/versions/types/serialization/xml.php @@ -17,17 +17,11 @@ */ use DCarbone\PHPFHIR\Enum\TypeKindEnum; -use DCarbone\PHPFHIR\Utilities\NameUtils; -/** @var \DCarbone\PHPFHIR\Enum\TypeKindEnum $typeKind */ /** @var \DCarbone\PHPFHIR\Version $version */ -/** @var \DCarbone\PHPFHIR\Version\Definition\Type $type */ -/** @var \DCarbone\PHPFHIR\Version\Definition\Type $parentType */ -/** @var string $typeClassName */ +/** @var \DCarbone\PHPFHIR\Version\Definition\Type $type; */ -$xmlName = NameUtils::getTypeXMLElementName($type); -$localProperties = $type->getLocalProperties()->getLocalPropertiesIterator(); -$properties = $type->getAllPropertiesIndexedIterator(); +$typeKind = $type->getKind(); ob_start(); @@ -37,19 +31,15 @@ [ 'version' => $version, 'type' => $type, - 'typeKind' => $typeKind, - 'parentType' => $parentType, - 'typeClassName' => $typeClassName ] ); -if (0 < count($properties)) : +if (count($type->getAllPropertiesIndexedIterator()) > 0) : echo require_with( PHPFHIR_TEMPLATE_VERSION_TYPES_SERIALIZATION_DIR . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'unserialize' . DIRECTORY_SEPARATOR . 'body.php', [ 'version' => $version, 'type' => $type, - 'properties' => $properties, ] ); endif; @@ -75,18 +65,15 @@ [ 'version' => $version, 'type' => $type, - 'parentType' => $parentType, ] ); - if (0 < count($localProperties)) { + if ($type->hasLocalProperties()) { echo require_with( PHPFHIR_TEMPLATE_VERSION_TYPES_SERIALIZATION_DIR . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'serialize' . DIRECTORY_SEPARATOR . 'body.php', [ 'version' => $version, 'type' => $type, - 'parentType' => $parentType, - 'localProperties' => $localProperties, ] ); } diff --git a/template/versions/types/serialization/xml/serialize/body.php b/template/versions/types/serialization/xml/serialize/body.php index 9d62cb65..fbeb2ecf 100644 --- a/template/versions/types/serialization/xml/serialize/body.php +++ b/template/versions/types/serialization/xml/serialize/body.php @@ -18,11 +18,8 @@ use DCarbone\PHPFHIR\Enum\TypeKindEnum; -/** @var \DCarbone\PHPFHIR\Config $config */ /** @var \DCarbone\PHPFHIR\Version $version */ /** @var \DCarbone\PHPFHIR\Version\Definition\Type $type */ -/** @var \DCarbone\PHPFHIR\Version\Definition\Type|null $parentType */ -/** @var \DCarbone\PHPFHIR\Version\Definition\Property[] $localProperties */ ob_start(); @@ -44,11 +41,11 @@ isCollection()) : ?> if ([] === $locs && [] !== ($vs = $this->getGetterName(); ?>())) { $xw->writeAttribute(self::getFieldConstantName(); ?>, $vs[0]->getFormattedValue()); - } else if (false !== ($idx = array_search(::ATTRIBUTE, $locs, true)) && [] !== ($vs = $this->getGetterName(); ?>()) && isset($vs[$idx])) { + } else if (false !== ($idx = array_search(::ATTRIBUTE, $locs, true)) && [] !== ($vs = $this->getGetterName(); ?>()) && isset($vs[$idx])) { $xw->writeAttribute(self::getFieldConstantName(); ?>, $vs[$idx]->getFormattedValue()); } - if (([] === $locs || (isset($locs[0]) && ::ATTRIBUTE === $locs[0])) && null !== ($v = $this->getGetterName(); ?>())) { + if (([] === $locs || (isset($locs[0]) && ::ATTRIBUTE === $locs[0])) && null !== ($v = $this->getGetterName(); ?>())) { $xw->writeAttribute(self::getFieldConstantName(); ?>, $v->getFormattedValue()); } isCollection()) : ?> if ([] === $locs && [] !== ($vs = $this->getGetterName(); ?>())) { $xw->writeAttribute(self::getFieldConstantName(); ?>, $vs[0]->getValue()?->getFormattedValue()); - } else if (false !== ($idx = array_search(::ATTRIBUTE, $locs, true)) && [] !== ($vs = $this->getGetterName(); ?>()) && isset($vs[$idx])) { + } else if (false !== ($idx = array_search(::ATTRIBUTE, $locs, true)) && [] !== ($vs = $this->getGetterName(); ?>()) && isset($vs[$idx])) { $xw->writeAttribute(self::getFieldConstantName(); ?>, $vs[$idx]->getValue()?->getFormattedValue()); } - if (([] === $locs || (isset($locs[0]) && ::ATTRIBUTE === $locs[0])) && null !== ($v = $this->getGetterName(); ?>())) { + if (([] === $locs || (isset($locs[0]) && ::ATTRIBUTE === $locs[0])) && null !== ($v = $this->getGetterName(); ?>())) { $xw->writeAttribute(self::getFieldConstantName(); ?>, $v->getValue()?->getFormattedValue()); } getLocalProperties()->getLocalPropertiesGenerator() as $property) : $pt = $property->getValueFHIRType(); // if this property has a "type"... @@ -102,9 +99,9 @@ elseif ($pt->hasPrimitiveParent() || $ptk->isOneOf(TypeKindEnum::LIST, TypeKindEnum::PRIMITIVE)) : ?> $locs = $this->_xmlLocations[self::getFieldConstantName(); ?>] ?? []; isCollection()) : ?> - if (([] === $locs || in_array(::ELEMENT, $locs, true)) && [] !== ($vs = $this->getGetterName(); ?>())) { + if (([] === $locs || in_array(::ELEMENT, $locs, true)) && [] !== ($vs = $this->getGetterName(); ?>())) { foreach($vs as $i => $v) { - if (!isset($locs[$i]) || ::ELEMENT === $locs[$i]) { + if (!isset($locs[$i]) || ::ELEMENT === $locs[$i]) { $xw->startElement(self::getFieldConstantName(); ?>); $v->xmlSerialize($xw, $config); $xw->endElement(); @@ -112,7 +109,7 @@ } } - if (([] === $locs || (isset($locs[0]) && ::ELEMENT === $locs[0])) && null !== ($v = $this->getGetterName(); ?>())) { + if (([] === $locs || (isset($locs[0]) && ::ELEMENT === $locs[0])) && null !== ($v = $this->getGetterName(); ?>())) { $xw->startElement(self::getFieldConstantName(); ?>); $v->xmlSerialize($xw, $config); $xw->endElement(); @@ -121,9 +118,9 @@ elseif ($ptk === TypeKindEnum::PRIMITIVE_CONTAINER) : ?> $locs = $this->_xmlLocations[self::getFieldConstantName(); ?>] ?? []; isCollection()) : ?> - if (([] === $locs || in_array(::ELEMENT, $locs, true)) && [] !== ($vs = $this->getGetterName(); ?>())) { + if (([] === $locs || in_array(::ELEMENT, $locs, true)) && [] !== ($vs = $this->getGetterName(); ?>())) { foreach($vs as $i => $v) { - if (!isset($locs[$i]) || ::ELEMENT === $locs[$i]) { + if (!isset($locs[$i]) || ::ELEMENT === $locs[$i]) { $xw->startElement(self::getFieldConstantName(); ?>); $v->xmlSerialize($xw, $config); $xw->endElement(); @@ -131,7 +128,7 @@ } } - if (([] === $locs || (isset($locs[0]) && ::ELEMENT === $locs[0])) && null !== ($v = $this->getGetterName(); ?>())) { + if (([] === $locs || (isset($locs[0]) && ::ELEMENT === $locs[0])) && null !== ($v = $this->getGetterName(); ?>())) { $xw->startElement(self::getFieldConstantName(); ?>); $v->xmlSerialize($xw, $config); $xw->endElement(); diff --git a/template/versions/types/serialization/xml/serialize/header.php b/template/versions/types/serialization/xml/serialize/header.php index 8a22c498..c525630a 100644 --- a/template/versions/types/serialization/xml/serialize/header.php +++ b/template/versions/types/serialization/xml/serialize/header.php @@ -20,25 +20,25 @@ /** @var \DCarbone\PHPFHIR\Version $version */ /** @var \DCarbone\PHPFHIR\Version\Definition\Type $type */ -/** @var \DCarbone\PHPFHIR\Version\Definition\Type $parentType */ $config = $version->getConfig(); -$namespace = $version->getFullyQualifiedName(false); -$typeKind = $type->getKind(); -$xmlName = NameUtils::getTypeXMLElementName($type); +$coreFiles = $config->getCoreFiles(); + +$xmlWriterClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_CLASSNAME_XML_WRITER); +$serializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG); ob_start(); ?> /** - * @param null|getFullyQualifiedName(true, PHPFHIR_CLASSNAME_XML_WRITER); ?> $xw - * @param null|getFullyQualifiedName(true, PHPFHIR_CLASSNAME_SERIALIZE_CONFIG); ?> $config - * @return getFullyQualifiedName(true, PHPFHIR_CLASSNAME_XML_WRITER); ?> + * @param null|getFullyQualifiedName(true); ?> $xw + * @param null|getFullyQualifiedName(true); ?> $config + * @return getFullyQualifiedName(true); ?> */ - public function xmlSerialize(null| $xw = null, null| $config = null): + public function xmlSerialize(null| $xw = null, null| $config = null): { if (null === $xw) { - $xw = new (); + $xw = new (); } if (!$xw->isOpen()) { $xw->openMemory(); diff --git a/template/versions/types/serialization/xml/serialize/resource_container.php b/template/versions/types/serialization/xml/serialize/resource_container.php index 0c4dbc3d..626e868f 100644 --- a/template/versions/types/serialization/xml/serialize/resource_container.php +++ b/template/versions/types/serialization/xml/serialize/resource_container.php @@ -22,21 +22,23 @@ /** @var \DCarbone\PHPFHIR\Version\Definition\Type $type */ $config = $version->getConfig(); -$namespace = $version->getFullyQualifiedName(false); -$localProperties = $type->getLocalProperties()->getLocalPropertiesIterator(); +$coreFiles = $config->getCoreFiles(); + +$xmlWriterClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_CLASSNAME_XML_WRITER); +$serializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG); ob_start(); ?> /** - * @param null|getFullyQualifiedName(true, PHPFHIR_CLASSNAME_XML_WRITER); ?> $xw - * @param null|getFullyQualifiedName(true, PHPFHIR_CLASSNAME_SERIALIZE_CONFIG); ?> $config - * @return getFullyQualifiedName(true, PHPFHIR_CLASSNAME_XML_WRITER); ?> + * @param null|getFullyQualifiedName(true); ?> $xw + * @param null|getFullyQualifiedName(true); ?> $config + * @return getFullyQualifiedName(true); ?> */ - public function xmlSerialize(null| $xw = null, null| $config = null): + public function xmlSerialize(null| $xw = null, null| $config = null): { if (null === $xw) { - $xw = new (); + $xw = new (); } if (!$xw->isOpen()) { $xw->openMemory(); @@ -48,7 +50,7 @@ public function xmlSerialize(null| $x if (null === $config) { $config = (new ())->getConfig()->getSerializeConfig(); } - +getLocalProperties()->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 6d5231de..5ed4752e 100644 --- a/template/versions/types/serialization/xml/unserialize/body.php +++ b/template/versions/types/serialization/xml/unserialize/body.php @@ -16,20 +16,15 @@ * limitations under the License. */ -/** @var \DCarbone\PHPFHIR\Version $version */ -/** @var \DCarbone\PHPFHIR\Version\Definition\Type $type */ -/** @var \DCarbone\PHPFHIR\Version\Definition\Property[] $properties */ - use DCarbone\PHPFHIR\Enum\TypeKindEnum; -$requireArgs = [ - 'version' => $version, -]; +/** @var \DCarbone\PHPFHIR\Version $version */ +/** @var \DCarbone\PHPFHIR\Version\Definition\Type $type */ ob_start(); ?> foreach ($element->children() as $n) { $childName = $n->getName(); - $property) : +getAllPropertiesIndexedIterator() as $i => $property) : $propConst = $property->getFieldConstantName(); $propType = $property->getValueFHIRType(); $setter = $property->getSetterName(); @@ -47,7 +42,7 @@ } }if (self:: === $childName) { - $type->(::xmlUnserialize($n, null, $config)hasPrimitiveParent() || $propType->getKind()->isOneOf(TypeKindEnum::PRIMITIVE, TypeKindEnum::LIST, TypeKindEnum::PRIMITIVE_CONTAINER)) : ?>, ::ELEMENT); + $type->(::xmlUnserialize($n, null, $config)hasPrimitiveParent() || $propType->getKind()->isOneOf(TypeKindEnum::PRIMITIVE, TypeKindEnum::LIST, TypeKindEnum::PRIMITIVE_CONTAINER)) : ?>, ::ELEMENT); }if (self:: === $childName) { @@ -65,7 +60,7 @@ } $attributes = $element->attributes(); - $property) : +getAllPropertiesIndexedIterator() as $i => $property) : $propConst = $property->getFieldConstantName(); $propType = $property->getValueFHIRType(); $setter = $property->getSetterName(); @@ -77,20 +72,20 @@ if ($propType->hasPrimitiveParent() || $propType->getKind()->isOneOf(TypeKindEnum::PRIMITIVE, TypeKindEnum::LIST, TypeKindEnum::PRIMITIVE_CONTAINER)) : ?> if (isset($attributes[self::])) { isCollection()) : ?> - $type->((string)$attributes[self::], ::ATTRIBUTE); + $type->((string)$attributes[self::], ::ATTRIBUTE); $pt = $type->getGetterName(); ?>(); if (null !== $pt) { - $pt->setValue((string)$attributes[self::], ::ATTRIBUTE); + $pt->setValue((string)$attributes[self::], ::ATTRIBUTE); } else { - $type->((string)$attributes[self::], ::ATTRIBUTE); + $type->((string)$attributes[self::], ::ATTRIBUTE); } } if (isset($attributes[self::getFieldConstantName(); ?>])) { - $type->setValue((string)$attributes[self::getFieldConstantName(); ?>], ::ATTRIBUTE); + $type->setValue((string)$attributes[self::getFieldConstantName(); ?>], ::ATTRIBUTE); } getConfig(); -$namespace = $version->getFullyQualifiedName(false); -$versionName = $version->getName(); +$coreFiles = $config->getCoreFiles(); + +$unserializeConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_ENCODING_CLASSNAME_UNSERIALIZE_CONFIG); ob_start(); ?> /** * @param null|string|\SimpleXMLElement $element * @param null|getFullyQualifiedClassName(true); ?> $type - * @param null|getFullyQualifiedName(true, PHPFHIR_CLASSNAME_UNSERIALIZE_CONFIG); ?> $config + * @param null|getFullyQualifiedName(true); ?> $config * @return null|getFullyQualifiedClassName(true); ?> * @throws \Exception */ - public static function xmlUnserialize(null|string|\SimpleXMLElement $element, null| $type = null, null| $config = null): null|self + public static function xmlUnserialize(null|string|\SimpleXMLElement $element, null| $type = null, null| $config = null): null|self { if (null === $element) { return null; @@ -52,7 +50,7 @@ public static function xmlUnserialize(null|string|\SimpleXMLElement $element, nu } if (null === $type) { $type = new static(null); - } else if (!($type instanceof )) { + } else if (!($type instanceof getClassName(); ?>)) { throw new \RuntimeException(sprintf( '%s::xmlUnserialize - $type must be instance of \\%s or null, %s seen.', ltrim(substr(__CLASS__, (int)strrpos(__CLASS__, '\\')), '\\'), diff --git a/template/versions/types/tests/integration/class.php b/template/versions/types/tests/integration/class.php index f46fe1e6..3d825cf3 100644 --- a/template/versions/types/tests/integration/class.php +++ b/template/versions/types/tests/integration/class.php @@ -67,9 +67,9 @@ ?> -use getFullyQualifiedName(false, PHPFHIR_CLASSNAME_CLIENT_CLIENT); ?>; -use getFullyQualifiedName(false, PHPFHIR_CLASSNAME_CLIENT_CONFIG); ?>; -use getFullyQualifiedName(false, PHPFHIR_ENUM_CLIENT_RESPONSE_FORMAT); ?>; +use getFullyQualifiedName(false, PHPFHIR_CLIENT_CLASSNAME_CLIENT); ?>; +use getFullyQualifiedName(false, PHPFHIR_CLIENT_CLASSNAME_CONFIG); ?>; +use getFullyQualifiedName(false, PHPFHIR_CLIENT_ENUM_RESPONSE_FORMAT); ?>; use getFullyQualifiedName(false, PHPFHIR_CLASSNAME_RESPONSE_PARSER); ?>; use getFullyQualifiedClassName(false); ?>; use getFullyQualifiedClassName(false); ?>; @@ -93,11 +93,11 @@ class extends TestCase /** @var getFullyQualifiedName(true, PHPFHIR_CLASSNAME_VERSION); ?> */ private $_version; - /** @var getFullyQualifiedName(true, PHPFHIR_CLASSNAME_CLIENT_CONFIG); ?> */ - private $_clientConfig; + /** @var getFullyQualifiedName(true, PHPFHIR_CLIENT_CLASSNAME_CONFIG); ?> */ + private $_clientConfig; - /** @var getFullyQualifiedName(true, PHPFHIR_CLASSNAME_CLIENT_CLIENT); ?> */ - private $_baseClient; + /** @var getFullyQualifiedName(true, PHPFHIR_CLIENT_CLASSNAME_CLIENT); ?> */ + private $_baseClient; /** @var getFullyQualifiedName(true, PHPFHIR_CLASSNAME_VERSION_API_CLIENT); ?> */ private $_client; @@ -113,8 +113,8 @@ protected function setUp(): void } $this->_testEndpoint = $endpoint; $this->_version = new (); - $this->_clientConfig = new (address: $endpoint); - $this->_baseClient = new ($this->_clientConfig); + $this->_clientConfig = new (address: $endpoint); + $this->_baseClient = new ($this->_clientConfig); $this->_client = new ( $this->_baseClient, $this->_version, @@ -134,7 +134,7 @@ protected function fetchResourceBundle(string $format): string $rc = $this->_client->readRaw( resourceType: ::getConstName(false); ?>, count: 5, - format: ::from($format), + format: ::from($format), ); $this->assertEmpty($rc->err, sprintf('curl error seen: %s', $rc->err)); if (404 === $rc->code) { diff --git a/template/versions/types/tests/validation/class.php b/template/versions/types/tests/validation/class.php index 3cb23de5..a02ad909 100644 --- a/template/versions/types/tests/validation/class.php +++ b/template/versions/types/tests/validation/class.php @@ -67,8 +67,8 @@ use getFullyQualifiedClassName(false); ?>; use getFullyQualifiedClassName(false); ?>; -use getFullyQualifiedName(false, PHPFHIR_CLASSNAME_CLIENT_CLIENT); ?>; -use getFullyQualifiedName(false, PHPFHIR_ENUM_CLIENT_RESPONSE_FORMAT); ?>; +use getFullyQualifiedName(false, PHPFHIR_CLIENT_CLASSNAME_CLIENT); ?>; +use getFullyQualifiedName(false, PHPFHIR_CLIENT_ENUM_RESPONSE_FORMAT); ?>; use getFullyQualifiedName(false, PHPFHIR_CLASSNAME_VERSION_API_CLIENT); ?>; use getFullyQualifiedName(false, PHPFHIR_ENUM_VERSION_TYPE); ?>; use getFullyQualifiedName(false, PHPFHIR_CLASSNAME_RESPONSE_PARSER); ?>; @@ -105,8 +105,8 @@ class extends TestCase /** @var getFullyQualifiedName(true, PHPFHIR_CLASSNAME_VERSION); ?> */ private $_version; - /** @var getFullyQualifiedName(true, PHPFHIR_CLASSNAME_CLIENT_CLIENT); ?> */ - private $_baseClient; + /** @var getFullyQualifiedName(true, PHPFHIR_CLIENT_CLASSNAME_CLIENT); ?> */ + private $_baseClient; /** @var getFullyQualifiedName(true, PHPFHIR_CLASSNAME_VERSION_API_CLIENT); ?> */ private $_client; @@ -122,7 +122,7 @@ protected function setUp(): void } $this->_testEndpoint = $endpoint; $this->_version = new (); - $this->_baseClient = new ($endpoint); + $this->_baseClient = new ($endpoint); $this->_client = new ( $this->_baseClient, $this->_version, @@ -169,7 +169,7 @@ protected function fetchResourceBundle(string $format): string if (isset($this->_fetchedResources[$format])) { return $this->_fetchedResources[$format]; } - $rc = $this->_client->readRaw(resourceType: ::getConstName(false); ?>, count: 5, format: ::from($format)); + $rc = $this->_client->readRaw(resourceType: ::getConstName(false); ?>, count: 5, format: ::from($format)); $this->assertEmpty($rc->err, sprintf('curl error seen: %s', $rc->err)); if (404 === $rc->code) { $this->markTestSkipped(sprintf('Endpoint "%s" has no resources of type "%s"', $this->_testEndpoint, ::getConstName(false); ?>->value)); diff --git a/template/versions/types/validation/methods.php b/template/versions/types/validation/methods.php index 85386007..ca012f17 100644 --- a/template/versions/types/validation/methods.php +++ b/template/versions/types/validation/methods.php @@ -19,8 +19,6 @@ /** @var \DCarbone\PHPFHIR\Version $version */ /** @var \DCarbone\PHPFHIR\Version\Definition\Type $type */ -use DCarbone\PHPFHIR\Enum\TypeKindEnum; - $typeNameConst = $type->getTypeNameConst(true); $typeKind = $type->getKind(); @@ -66,7 +64,7 @@ public function _getValidationErrors(): array if ($property->isCollection()) : ?> if (isset($validationRules[self::FIELD_VALUE]) && [] !== ($vs = $this->getGetterName(); ?>())) { foreach($vs as $i => $v) { - $err = ::performValidation(getMemberOf()->getTypeNameConst(true); ?>, self::getFieldConstantName(); ?>, $rule, $constraint, $v); + $err = ::validateField(getMemberOf()->getTypeNameConst(true); ?>, self::getFieldConstantName(); ?>, $rule, $constraint, $v); if (null !== $err) { $key = sprintf('%s.%d', self::getFieldConstantName(); ?>, $i); if (!isset($errs[$key])) { @@ -80,7 +78,7 @@ public function _getValidationErrors(): array else : ?> if (isset($validationRules[self::FIELD_VALUE]) && null !== $this->value) { foreach($validationRules[self::FIELD_VALUE] as $rule => $constraint) { - $err = ::performValidation(getMemberOf()->getTypeNameConst(true); ?>, self::getFieldConstantName(); ?>, $rule, $constraint, $this->getFormattedValue()); + $err = ::validateField(getMemberOf()->getTypeNameConst(true); ?>, self::getFieldConstantName(); ?>, $rule, $constraint, $this->getFormattedValue()); if (null !== $err) { if (!isset($errs[self::FIELD_VALUE])) { $errs[self::FIELD_VALUE] = []; @@ -116,7 +114,7 @@ public function _getValidationErrors(): array if (isset($validationRules[self::getFieldConstantName(); ?>])) { $v = $this->getGetterName(); ?>(); foreach($validationRules[self::getFieldConstantName(); ?>] as $rule => $constraint) { - $err = ::performValidation(getTypeNameConst(true); ?>, self::getFieldConstantName(); ?>, $rule, $constraint, $v); + $err = ::validateField(getTypeNameConst(true); ?>, self::getFieldConstantName(); ?>, $rule, $constraint, $v); if (null !== $err) { if (!isset($errs[self::getFieldConstantName(); ?>])) { $errs[self::getFieldConstantName(); ?>] = [];