Skip to content

Commit

Permalink
some thoughts....xml location implementation leaves a bit to be desired.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcarbone committed Jan 25, 2025
1 parent 997b746 commit cecf0cb
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 23 deletions.
2 changes: 2 additions & 0 deletions src/Builder/TypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

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 @@ -62,6 +63,7 @@ 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: 25 additions & 0 deletions src/Enum/DefaultValueXMLLocation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php declare(strict_types=1);

namespace DCarbone\PHPFHIR\Enum;

/*
* Copyright 2025 Daniel Carbone ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

enum DefaultValueXMLLocation : string
{
case ATTRIBUTE = 'attribute';
CASE ELEMENT = 'element';
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

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 @@ -77,6 +78,7 @@ 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,6 +19,7 @@
*/

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 @@ -82,6 +83,7 @@ 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,6 +19,7 @@
*/

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 @@ -139,6 +140,7 @@ 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
39 changes: 26 additions & 13 deletions src/Version/Definition/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* 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 @@ -30,6 +31,8 @@ class Property
private Type $_memberOf;
private Property $_overloads;

private DefaultValueXMLLocation $_defaultValueXMLLocation;

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

Expand All @@ -49,17 +52,18 @@ class Property
private null|string $namespace = null;// NOTE: not a php 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 = '')
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 = '')
{
if ('' === $name && '' === $ref) {
throw new \InvalidArgumentException(sprintf(
Expand All @@ -70,8 +74,9 @@ public function __construct(Type $memberOf,
}

$this->_memberOf = $memberOf;
$this->sourceSXE = $sxe;
$this->sourceFilename = $sourceFilename;
$this->_sourceSXE = $sxe;
$this->_sourceFilename = $sourceFilename;
$this->_defaultValueXMLLocation = $defaultValueXMLLocation;

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

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

/**
* @return string|null
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Version/Definition/SourceTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ trait SourceTrait
*
* @var null|\SimpleXMLElement
*/
protected null|\SimpleXMLElement $sourceSXE;
protected null|\SimpleXMLElement $_sourceSXE;

/**
* Name of file in definition this type was parsed from
* @var string
*/
protected string $sourceFilename;
protected string $_sourceFilename;

/**
* @return null|\SimpleXMLElement
*/
public function getSourceSXE(): null|\SimpleXMLElement
{
return $this->sourceSXE;
return $this->_sourceSXE;
}

/**
* @return string
*/
public function getSourceFilename(): string
{
return $this->sourceFilename;
return $this->_sourceFilename;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Version/Definition/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public function __construct(Version $version,
}
$this->_version = $version;
$this->_fhirName = $fhirName;
$this->sourceSXE = $sourceSXE;
$this->sourceFilename = $sourceFilename;
$this->_sourceSXE = $sourceSXE;
$this->_sourceFilename = $sourceFilename;
$this->_properties = new Properties($this);
$this->_enumeration = new Enumeration();
}
Expand Down
7 changes: 3 additions & 4 deletions template/versions/types/methods/constructor.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
// only define constructor if this primitive does not have a parent.
if (null === $parentType) : ?>

/* <?php echo basename(__FILE__) . ':' . __LINE__; ?> */
/**
* <?php echo $typeClassName; ?> Constructor
* @param <?php echo TypeHintUtils::primitivePHPValueTypeSetterDoc($version, $primitiveType, true); ?> $value
Expand All @@ -62,6 +63,7 @@ public function __construct(<?php echo TypeHintUtils::buildSetterParameterHint($
endif;
else : ?>

/* <?php echo basename(__FILE__) . ':' . __LINE__; ?> */
/**
* <?php echo $typeClassName; ?> Constructor
<?php foreach($type->getAllPropertiesIndexedIterator() as $property) :
Expand Down Expand Up @@ -97,10 +99,7 @@ public function __construct(<?php foreach($type->getAllPropertiesIndexedIterator
}
<?php endif;

foreach($properties->getIterator() as $property) :
if ($property->getOverloadedProperty()) {
continue;
} ?>
foreach($properties->getIterator() as $property) : ?>
if (null !== $<?php echo $property->getName(); ?>) {
<?php if ($property->isCollection()) : ?>
$this->set<?php echo ucfirst($property->getName()); ?>(...$<?php echo $property->getName(); ?>);
Expand Down

0 comments on commit cecf0cb

Please sign in to comment.