Skip to content

Commit

Permalink
simplifying resource container implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dcarbone committed Jan 6, 2025
1 parent 6f6df20 commit 86ab3bc
Show file tree
Hide file tree
Showing 141 changed files with 395 additions and 198 deletions.
2 changes: 1 addition & 1 deletion src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Builder/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Builder;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Builder/Imports.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Builder;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Builder/TypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Builder;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/ConfigKeyEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR;

/*
* Copyright 2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2024-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/CoreFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR;

/*
* Copyright 2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2024-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/CoreFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR;

/*
* Copyright 2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2024-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Enum/AttributeNameEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Enum;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Enum/ElementNameEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Enum;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Enum/PrimitiveTypeEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Enum;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Enum/PropertyUseEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Enum;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
19 changes: 9 additions & 10 deletions src/Enum/TypeKindEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Enum;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,9 +48,8 @@ enum TypeKindEnum: string
// treated a bit different
case PHPFHIR_XHTML = 'phpfhir_xhtml';

private const _DSTU1_CONTAINER_TYPE = self::RESOURCE_INLINE;

private const _CONTAINER_TYPE = self::RESOURCE_CONTAINER;
private const _DSTU1_RESOURCE_CONTAINER_TYPE = self::RESOURCE_INLINE;
private const _RESOURCE_CONTAINER_TYPE = self::RESOURCE_CONTAINER;

/**
* Returns true if the provided FHIR type name is the "container" type for the provided version.
Expand All @@ -62,9 +61,9 @@ enum TypeKindEnum: string
public static function isContainerTypeName(Version $version, string $fhirName): bool
{
if ($version->getSourceMetadata()->isDSTU1()) {
return $fhirName === self::_DSTU1_CONTAINER_TYPE->value;
return $fhirName === self::_DSTU1_RESOURCE_CONTAINER_TYPE->value;
}
return $fhirName === self::_CONTAINER_TYPE->value;
return $fhirName === self::_RESOURCE_CONTAINER_TYPE->value;
}

/**
Expand All @@ -77,16 +76,16 @@ public function isOneOf(TypeKindEnum|string ...$other): bool
}

/**
* Returns true if this kind is the "container" kind for the provided FHIR version.
* Returns true if this kind is the "resource container" kind for the provided FHIR version.
*
* @param \DCarbone\PHPFHIR\Version $version
* @return bool
*/
public function isContainer(Version $version): bool
public function isResourceContainer(Version $version): bool
{
if ($version->getSourceMetadata()->isDSTU1()) {
return $this === self::_DSTU1_CONTAINER_TYPE;
return $this === self::_DSTU1_RESOURCE_CONTAINER_TYPE;
}
return $this === self::_CONTAINER_TYPE;
return $this === self::_RESOURCE_CONTAINER_TYPE;
}
}
2 changes: 1 addition & 1 deletion src/LogLevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR;

/*
* Copyright 2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2024-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
5 changes: 4 additions & 1 deletion src/Render/Templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Render;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -55,6 +55,9 @@ public static function renderVersionXHTMLTypeClass(Version $version, Types $type
*/
public static function renderVersionTypeClass(Version $version, Types $types, Type $type): string
{
if ($type->getKind()->isResourceContainer($version)) {
return require PHPFHIR_TEMPLATE_VERSION_TYPES_DIR . DIRECTORY_SEPARATOR . 'class_resource_container.php';
}
return require PHPFHIR_TEMPLATE_VERSION_TYPES_DIR . DIRECTORY_SEPARATOR . 'class_default.php';
}

Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/DocumentationUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Utilities;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/ExceptionUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Utilities;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/FileUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Utilities;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
36 changes: 26 additions & 10 deletions src/Utilities/ImportUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Utilities;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,17 +48,12 @@ public static function buildVersionTypeImports(Type $type): void
$typeKind = $type->getKind();

if (!$type->isAbstract()) {
$imports->addCoreFileImportsByName(PHPFHIR_ENCODING_CLASSNAME_XML_WRITER);
$imports->addCoreFileImportsByName(PHPFHIR_ENCODING_ENUM_XML_LOCATION);
$imports->addCoreFileImportsByName(
PHPFHIR_ENCODING_CLASSNAME_XML_WRITER,
PHPFHIR_ENCODING_ENUM_XML_LOCATION,
);
}

$imports->addVersionCoreFileImportsByName($type->getVersion(), PHPFHIR_CLASSNAME_VERSION);
$imports->addVersionCoreFileImportsByName($type->getVersion(), PHPFHIR_CLASSNAME_VERSION_CONSTANTS);
$imports->addCoreFileImportsByName(PHPFHIR_ENCODING_CLASSNAME_UNSERIALIZE_CONFIG);
$imports->addCoreFileImportsByName(PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG);

$imports->addCoreFileImportsByName(PHPFHIR_INTERFACE_TYPE);

foreach ($type->getDirectlyImplementedInterfaces() as $interface => $namespace) {
$imports->addImport($namespace, $interface);
}
Expand All @@ -67,12 +62,33 @@ public static function buildVersionTypeImports(Type $type): void
$imports->addImport($namespace, $trait);
}

$imports->addVersionCoreFileImportsByName(
$type->getVersion(),
PHPFHIR_CLASSNAME_VERSION,
PHPFHIR_CLASSNAME_VERSION_CONSTANTS,
);

$imports->addCoreFileImportsByName(
PHPFHIR_ENCODING_CLASSNAME_UNSERIALIZE_CONFIG,
PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG,
PHPFHIR_INTERFACE_TYPE,
);

if (($type->isCommentContainer() && !$type->hasCommentContainerParent()) ||
$type->hasLocalPropertiesWithValidations() ||
($typeKind->isOneOf(TypeKindEnum::PRIMITIVE) && !$type->hasPrimitiveParent())) {
$imports->addCoreFileImportsByName(PHPFHIR_CLASSNAME_CONSTANTS);
}

if ($typeKind->isResourceContainer($type->getVersion())) {
$imports->addVersionCoreFileImportsByName(
$type->getVersion(),
PHPFHIR_CLASSNAME_VERSION_TYPE_MAP,
PHPFHIR_INTERFACE_VERSION_CONTAINED_TYPE,
);
return;
}

if ($parentType = $type->getParentType()) {
$imports->addImport(
$parentType->getFullyQualifiedNamespace(false),
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/NameUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Utilities;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/TypeHintUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Utilities;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR;

/*
* Copyright 2018-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2018-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Version/DefaultConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Version;

/*
* Copyright 2018-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2018-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Version/DefaultConfigKeyEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Version;

/*
* Copyright 2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2024-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Version/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Version;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Version\Definition\Decorator;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Version\Definition\Decorator;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Version\Definition\Decorator;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Version\Definition\Decorator;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Version\Definition\Decorator;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace DCarbone\PHPFHIR\Version\Definition\Decorator;

/*
* Copyright 2016-2024 Daniel Carbone (daniel.p.carbone@gmail.com)
* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit 86ab3bc

Please sign in to comment.