Skip to content

Commit

Permalink
going back to something similar to v3 with xml location. needs more w…
Browse files Browse the repository at this point in the history
…ork and is still probably not good enough.
  • Loading branch information
dcarbone committed Jan 27, 2025
1 parent 9e57928 commit 54227ce
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 200 deletions.
2 changes: 0 additions & 2 deletions src/Builder/TypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/

use DCarbone\PHPFHIR\Config;
use DCarbone\PHPFHIR\Enum\DefaultValueXMLLocation;
use DCarbone\PHPFHIR\Version\Definition\Property;
use DCarbone\PHPFHIR\Version\Definition\Type;
use DCarbone\PHPFHIR\Version;
Expand Down Expand Up @@ -63,7 +62,6 @@ private static function buildPrimitiveType(Config $config,
memberOf: $type,
sxe: $sxe,
sourceFilename: $sourceFilename,
defaultValueXMLLocation: DefaultValueXMLLocation::ATTRIBUTE,
name: PHPFHIR_VALUE_PROPERTY_NAME,
);
$type->getProperties()->addOrReturnProperty($value);
Expand Down
25 changes: 0 additions & 25 deletions src/Enum/DefaultValueXMLLocation.php

This file was deleted.

38 changes: 31 additions & 7 deletions src/Utilities/ImportUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,30 @@ public static function compileImportStatements(Imports $imports): string
return implode("\n", $stmts) . "\n";
}

public static function buildVersionPrimitiveTypeImports(Version $version, Type $type): void
{
$imports = $type->getImports();

$imports
->addCoreFileImportsByName(
PHPFHIR_CLASSNAME_CONSTANTS,
PHPFHIR_CLASSNAME_VALIDATOR,
)
->addVersionCoreFileImportsByName(
$version,
PHPFHIR_VERSION_CLASSNAME_VERSION_CONSTANTS,
);

if (!$type->hasParent()) {
$imports->addCoreFileImportsByName(
PHPFHIR_TRAIT_SOURCE_XMLNS,
PHPFHIR_TYPES_INTERFACE_PRIMITIVE_TYPE,
);
} else {
$imports->addVersionTypeImports($type->getParentType());
}
}

public static function buildVersionTypeImports(Version $version, Type $type): void
{
$imports = $type->getImports();
Expand All @@ -51,6 +75,11 @@ public static function buildVersionTypeImports(Version $version, Type $type): vo
return;
}

if ($type->isPrimitiveOrListType() || $type->hasPrimitiveOrListParent()) {
self::buildVersionPrimitiveTypeImports($version, $type);
return;
}

$typeKind = $type->getKind();

if (!$type->isAbstract()) {
Expand Down Expand Up @@ -101,13 +130,8 @@ public static function buildVersionTypeImports(Version $version, Type $type): vo
);
}

if ($type->isValueContainer()
|| $type->hasValueContainerParent()
|| $type->hasPrimitiveContainerParent()
|| $typeKind->isOneOf(TypeKindEnum::PRIMITIVE, TypeKindEnum::LIST, TypeKindEnum::PRIMITIVE_CONTAINER)) {
if (!$type->hasValueContainerParent() && !$type->hasPrimitiveContainerParent()) {
$imports->addCoreFileImportsByName(PHPFHIR_ENCODING_TRAIT_VALUE_XML_LOCATION);
}
if ($type->isPrimitiveOrListType() || $type->isValueContainer() || $type->isPrimitiveContainer()) {
$imports->addCoreFileImportsByName(PHPFHIR_ENCODING_TRAIT_VALUE_XML_LOCATION);
}

if ($restrictionBaseType = $type->getRestrictionBaseFHIRType()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/

use DCarbone\PHPFHIR\Config;
use DCarbone\PHPFHIR\Enum\DefaultValueXMLLocation;
use DCarbone\PHPFHIR\Version\Definition\Property;
use DCarbone\PHPFHIR\Version\Definition\Type;
use DCarbone\PHPFHIR\Version\Definition\Types;
Expand Down Expand Up @@ -78,7 +77,6 @@ public static function decorate(Config $config,
memberOf: $type,
sxe: $attributeElement,
sourceFilename: $type->getSourceFilename(),
defaultValueXMLLocation: DefaultValueXMLLocation::ATTRIBUTE,
name: $name,
use: $use,
valueFHIRTypeName: $valueFHIRTypeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/

use DCarbone\PHPFHIR\Config;
use DCarbone\PHPFHIR\Enum\DefaultValueXMLLocation;
use DCarbone\PHPFHIR\Version\Definition\Property;
use DCarbone\PHPFHIR\Version\Definition\Type;
use DCarbone\PHPFHIR\Version\Definition\Types;
Expand Down Expand Up @@ -83,7 +82,6 @@ public static function decorate(Config $config,
memberOf: $type,
sxe: $element,
sourceFilename: $type->getSourceFilename(),
defaultValueXMLLocation: DefaultValueXMLLocation::ELEMENT,
name: $name,
ref: $ref,
minOccurs: $minOccurs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/

use DCarbone\PHPFHIR\Config;
use DCarbone\PHPFHIR\Enum\DefaultValueXMLLocation;
use DCarbone\PHPFHIR\Version\Definition\Property;
use DCarbone\PHPFHIR\Version\Definition\Type;
use DCarbone\PHPFHIR\Version\Definition\Types;
Expand Down Expand Up @@ -140,7 +139,6 @@ public static function decorate(Config $config, Types $types, Type $type, Simple
memberOf: $type,
sxe: $element,
sourceFilename: $type->getSourceFilename(),
defaultValueXMLLocation: DefaultValueXMLLocation::ELEMENT,
name: $name,
ref: $ref,
minOccurs: $minOccurs,
Expand Down
76 changes: 32 additions & 44 deletions src/Version/Definition/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* limitations under the License.
*/

use DCarbone\PHPFHIR\Enum\DefaultValueXMLLocation;
use DCarbone\PHPFHIR\Enum\PropertyUseEnum;
use DCarbone\PHPFHIR\Enum\TypeKindEnum;
use DCarbone\PHPFHIR\Utilities\NameUtils;
Expand All @@ -31,13 +30,11 @@ class Property
private Type $_memberOf;
private Property $_overloads;

private DefaultValueXMLLocation $_defaultValueXMLLocation;

private null|string $_name = null;
private null|string $_ref = null;

private null|string $valueFHIRTypeName = null;
private ?Type $valueFHIRType = null;
private null|string $_valueFHIRTypeName = null;
private ?Type $_valueFHIRType = null;
private null|string $rawPHPValue = null;

private int $minOccurs = 0;
Expand All @@ -52,18 +49,17 @@ class Property
private null|string $namespace = null;// NOTE: not a php namespace


public function __construct(Type $memberOf,
\SimpleXMLElement $sxe,
string $sourceFilename,
DefaultValueXMLLocation $defaultValueXMLLocation,
string $name = '',
string $ref = '',
string|PropertyUseEnum $use = PropertyUseEnum::OPTIONAL,
string|int $minOccurs = 0,
string|int $maxOccurs = '',
string $valueFHIRTypeName = '',
string $fixed = '',
string $namespace = '')
public function __construct(Type $memberOf,
\SimpleXMLElement $sxe,
string $sourceFilename,
string $name = '',
string $ref = '',
string|PropertyUseEnum $use = PropertyUseEnum::OPTIONAL,
string|int $minOccurs = 0,
string|int $maxOccurs = '',
string $valueFHIRTypeName = '',
string $fixed = '',
string $namespace = '')
{
if ('' === $name && '' === $ref) {
throw new \InvalidArgumentException(sprintf(
Expand All @@ -76,7 +72,6 @@ public function __construct(Type $memberOf,
$this->_memberOf = $memberOf;
$this->_sourceSXE = $sxe;
$this->_sourceFilename = $sourceFilename;
$this->_defaultValueXMLLocation = $defaultValueXMLLocation;

if ('' !== $name) {
$this->_name = $name;
Expand Down Expand Up @@ -122,14 +117,6 @@ public function getMemberOf(): Type
return $this->_memberOf;
}

/**
* @return \DCarbone\PHPFHIR\Enum\DefaultValueXMLLocation
*/
public function getDefaultValueXMLLocation(): DefaultValueXMLLocation
{
return $this->_defaultValueXMLLocation;
}

/**
* @return string|null
*/
Expand All @@ -149,7 +136,7 @@ public function setName(string $name): self
throw new \InvalidArgumentException(
sprintf(
'Type "%s" Property $name cannot be empty',
$this->valueFHIRType->getFHIRName()
$this->_valueFHIRType->getFHIRName()
)
);
}
Expand All @@ -173,7 +160,7 @@ public function getExtName(): null|string
*/
public function getValueFHIRTypeName(): null|string
{
return $this->valueFHIRTypeName;
return $this->_valueFHIRTypeName;
}

/**
Expand All @@ -185,7 +172,7 @@ public function setValueFHIRTypeName(string $valueFHIRTypeName): Property
if ('' === $valueFHIRTypeName) {
$valueFHIRTypeName = null;
}
$this->valueFHIRTypeName = $valueFHIRTypeName;
$this->_valueFHIRTypeName = $valueFHIRTypeName;
return $this;
}

Expand All @@ -194,17 +181,17 @@ public function setValueFHIRTypeName(string $valueFHIRTypeName): Property
*/
public function getValueFHIRType(): ?Type
{
return $this->valueFHIRType;
return $this->_valueFHIRType;
}

/**
* @param \DCarbone\PHPFHIR\Version\Definition\Type $valueFHIRType
* @param \DCarbone\PHPFHIR\Version\Definition\Type $_valueFHIRType
* @return \DCarbone\PHPFHIR\Version\Definition\Property
*/
public function setValueFHIRType(Type $valueFHIRType): Property
public function setValueFHIRType(Type $_valueFHIRType): Property
{
$this->valueFHIRType = $valueFHIRType;
$this->valueFHIRTypeName = $valueFHIRType->getFHIRName();
$this->_valueFHIRType = $_valueFHIRType;
$this->_valueFHIRTypeName = $_valueFHIRType->getFHIRName();
return $this;
}

Expand Down Expand Up @@ -285,8 +272,8 @@ public function getPattern(): null|string
if (isset($this->pattern)) {
return $this->pattern;
}
if (isset($this->valueFHIRType)) {
return $this->valueFHIRType->getPattern();
if (isset($this->_valueFHIRType)) {
return $this->_valueFHIRType->getPattern();
}
return null;
}
Expand Down Expand Up @@ -352,7 +339,7 @@ public function setRef(string $ref): Property
throw new \InvalidArgumentException(
sprintf(
'Type "%s" Property $ref cannot be empty',
$this->valueFHIRType->getFHIRName()
$this->_valueFHIRType->getFHIRName()
)
);
}
Expand Down Expand Up @@ -519,12 +506,13 @@ public function getOverloadedProperty(): null|Property
*/
public function requiresXMLLocation(): bool
{
return $this->_memberOf->hasPrimitiveOrListParent()
|| $this->_memberOf->getKind()->isOneOf(
TypeKindEnum::PRIMITIVE_CONTAINER,
TypeKindEnum::PRIMITIVE,
TypeKindEnum::LIST,
);
$propType = $this->getValueFHIRType();
if (null === $propType || $this->isCollection()) {
return false;
}
return $propType->hasPrimitiveOrListParent()
|| $propType->isPrimitiveContainer()
|| $propType->isPrimitiveOrListType();
}

/**
Expand All @@ -540,7 +528,7 @@ public function defaultXMLLocationEnumValue(): string
));
}

return $this->_memberOf->isValueContainer() ? 'ELEMENT' : 'ATTRIBUTE';
return $this->getValueFHIRType()->isValueContainer() ? 'ELEMENT' : 'ATTRIBUTE';
}

/**
Expand Down
7 changes: 0 additions & 7 deletions src/Version/Definition/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -880,13 +880,6 @@ public function getDirectlyUsedTraits(): array
->getFullyQualifiedNamespace(false);
}

if (($this->isValueContainer() || $this->isPrimitiveOrListType() || $this->isPrimitiveContainer())
&& !($this->hasValueContainerParent() || $this->hasPrimitiveContainerParent() || $this->hasPrimitiveOrListParent())) {
$traits[PHPFHIR_ENCODING_TRAIT_VALUE_XML_LOCATION] = $coreFiles
->getCoreFileByEntityName(PHPFHIR_ENCODING_TRAIT_VALUE_XML_LOCATION)
->getFullyQualifiedNamespace(false);
}

return $traits;
}

Expand Down
1 change: 0 additions & 1 deletion src/Version/Definition/Types.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

use ArrayIterator;
use Countable;
use DCarbone\PHPFHIR\Config;
use DCarbone\PHPFHIR\Version;
use DCarbone\PHPFHIR\Enum\TypeKindEnum;

Expand Down
13 changes: 0 additions & 13 deletions template/core/types/interface_primitive_type.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,6 @@ public function _getValidationErrors(): array;
*/
public function _getFormattedValue(): string;

/**
* Set the XML location of this element's value when serializing
*
* @param <?php echo $valueXMLLocationEnum->getFullyQualifiedName(true); ?> $valueXMLLocation
*/
public function _setValueXMLLocation(<?php echo $valueXMLLocationEnum->getEntityName(); ?> $valueXMLLocation): void;

/**
* @return null|<?php echo $valueXMLLocationEnum->getFullyQualifiedName(true); ?>

*/
public function _getValueXMLLocation(): null|<?php echo $valueXMLLocationEnum->getEntityName(); ?>;

/**
* @return string
*/
Expand Down
Loading

0 comments on commit 54227ce

Please sign in to comment.