Skip to content

Commit 751bc78

Browse files
committed
working through some ideas
1 parent c668ec3 commit 751bc78

File tree

21 files changed

+364
-113
lines changed

21 files changed

+364
-113
lines changed

files/constants.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,23 @@
6565
// Core interfaces, traits, and classes
6666
const PHPFHIR_TEMPLATE_CORE_DIR = PHPFHIR_TEMPLATE_DIR . DIRECTORY_SEPARATOR . 'core';
6767

68-
// Type rendering
69-
const PHPFHIR_TEMPLATE_TYPES_DIR = PHPFHIR_TEMPLATE_DIR . DIRECTORY_SEPARATOR . 'types';
70-
const PHPFHIR_TEMPLATE_TYPES_PROPERTIES_DIR = PHPFHIR_TEMPLATE_TYPES_DIR . DIRECTORY_SEPARATOR . 'properties';
71-
const PHPFHIR_TEMPLATE_TYPES_METHODS_DIR = PHPFHIR_TEMPLATE_TYPES_DIR . DIRECTORY_SEPARATOR . 'methods';
72-
const PHPFHIR_TEMPLATE_TYPES_CONSTRUCTORS_DIR = PHPFHIR_TEMPLATE_TYPES_METHODS_DIR . DIRECTORY_SEPARATOR . 'constructors';
73-
const PHPFHIR_TEMPLATE_TYPES_SERIALIZATION_DIR = PHPFHIR_TEMPLATE_TYPES_DIR . DIRECTORY_SEPARATOR . 'serialization';
74-
const PHPFHIR_TEMPLATE_TYPES_VALIDATION_DIR = PHPFHIR_TEMPLATE_TYPES_DIR . DIRECTORY_SEPARATOR . 'validation';
68+
// Version interfaces, traits, and enums
69+
const PHHPFHIR_TEMPLATE_VERSIONS_DIR = PHPFHIR_TEMPLATE_DIR . DIRECTORY_SEPARATOR . 'versions';
70+
const PHPFHIR_TEMPLATE_VERSIONS_CORE_DIR = PHHPFHIR_TEMPLATE_VERSIONS_DIR . DIRECTORY_SEPARATOR . 'core';
71+
72+
// Version type rendering
73+
const PHPFHIR_TEMPLATE_VERSION_TYPES_DIR = PHHPFHIR_TEMPLATE_VERSIONS_DIR . DIRECTORY_SEPARATOR . 'types';
74+
const PHPFHIR_TEMPLATE_VERSION_TYPES_PROPERTIES_DIR = PHPFHIR_TEMPLATE_VERSION_TYPES_DIR . DIRECTORY_SEPARATOR . 'properties';
75+
const PHPFHIR_TEMPLATE_VERSION_TYPES_METHODS_DIR = PHPFHIR_TEMPLATE_VERSION_TYPES_DIR . DIRECTORY_SEPARATOR . 'methods';
76+
const PHPFHIR_TEMPLATE_VERSION_TYPES_CONSTRUCTORS_DIR = PHPFHIR_TEMPLATE_VERSION_TYPES_METHODS_DIR . DIRECTORY_SEPARATOR . 'constructors';
77+
const PHPFHIR_TEMPLATE_VERSION_TYPES_SERIALIZATION_DIR = PHPFHIR_TEMPLATE_VERSION_TYPES_DIR . DIRECTORY_SEPARATOR . 'serialization';
78+
const PHPFHIR_TEMPLATE_VERSION_TYPES_VALIDATION_DIR = PHPFHIR_TEMPLATE_VERSION_TYPES_DIR . DIRECTORY_SEPARATOR . 'validation';
7579

7680

7781
// Fhir type test templates
78-
const PHPFHIR_TEMPLATE_TYPE_TESTS_DIR = PHPFHIR_TEMPLATE_TYPES_DIR . DIRECTORY_SEPARATOR . 'tests';
82+
const PHPFHIR_TEMPLATE_VERSION_TYPE_TESTS_DIR = PHPFHIR_TEMPLATE_VERSION_TYPES_DIR . DIRECTORY_SEPARATOR . 'tests';
7983

8084
// Core class names
81-
const PHPFHIR_CLASSNAME_VERSION = 'PHPFHIRVersion';
8285
const PHPFHIR_CLASSNAME_VERSIONS = 'PHPFHIRVersions';
8386
const PHPFHIR_CLASSNAME_AUTOLOADER = 'PHPFHIRAutoloader';
8487
const PHPFHIR_CLASSNAME_CONFIG = 'PHPFHIRConfig';
@@ -92,6 +95,9 @@
9295
const PHPFHIR_CLASSNAME_DEBUG_CLIENT = 'PHPFHIRDebugClient';
9396

9497
// Core interface names
98+
const PHPFHIR_INTERFACE_TYPE_MAP = 'PHPFHIRTypeMapInterface';
99+
const PHPFHIR_INTERFACE_RESPONSE_PARSER = 'PPHPFHIRResponseParserInterface';
100+
const PHPFHIR_INTERFACE_FHIR_VERSION = 'PHPFHIRVersionInterface';
95101
const PHPFHIR_INTERFACE_TYPE = 'PHPFHIRTypeInterface';
96102
const PHPFHIR_INTERFACE_CONTAINED_TYPE = 'PHPFHIRContainedTypeInterface';
97103
const PHPFHIR_INTERFACE_COMMENT_CONTAINER = 'PHPFHIRCommentContainerInterface';
@@ -111,6 +117,8 @@
111117
const PHPFHIR_ENUM_API_RESOURCE_LIST = 'PHPFHIRApiResourceListEnum';
112118
const PHPFHIR_ENUM_API_SORT = 'PHPFHIRApiSortEnum';
113119

120+
// Version Co
121+
114122
// validation constants
115123
const PHPFHIR_VALIDATION_ENUM = 'enum';
116124
const PHPFHIR_VALIDATION_ENUM_NAME = 'VALIDATE_ENUM';

src/Render/Templates.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static function renderCoreType(string $coreFilename, Config $config): str
4949
*/
5050
public static function renderXhtmlTypeClass(Config $config, Version $version, Types $types, Type $type): string
5151
{
52-
return require PHPFHIR_TEMPLATE_TYPES_DIR . DIRECTORY_SEPARATOR . 'class_xhtml.php';
52+
return require PHPFHIR_TEMPLATE_VERSION_TYPES_DIR . DIRECTORY_SEPARATOR . 'class_xhtml.php';
5353
}
5454

5555
/**
@@ -61,7 +61,7 @@ public static function renderXhtmlTypeClass(Config $config, Version $version, Ty
6161
*/
6262
public static function renderFhirTypeClass(Config $config, Version $version, Types $types, Type $type): string
6363
{
64-
return require PHPFHIR_TEMPLATE_TYPES_DIR . DIRECTORY_SEPARATOR . 'class_default.php';
64+
return require PHPFHIR_TEMPLATE_VERSION_TYPES_DIR . DIRECTORY_SEPARATOR . 'class_default.php';
6565
}
6666

6767
/**
@@ -74,6 +74,6 @@ public static function renderFhirTypeClass(Config $config, Version $version, Typ
7474
*/
7575
public static function renderFhirTypeClassTest(Config $config, Version $version, Types $types, Type $type, TestType $testType): string
7676
{
77-
return require PHPFHIR_TEMPLATE_TYPE_TESTS_DIR . DIRECTORY_SEPARATOR . $testType->value . DIRECTORY_SEPARATOR .'class.php';
77+
return require PHPFHIR_TEMPLATE_VERSION_TYPE_TESTS_DIR . DIRECTORY_SEPARATOR . $testType->value . DIRECTORY_SEPARATOR .'class.php';
7878
}
7979
}

src/Version.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ public function getFullyQualifiedTestsName(TestType $testType, bool $leadingSlas
178178
return $this->getFullyQualifiedName($leadingSlash, $testType->namespaceSlug(), ...$bits);
179179
}
180180

181+
/**
182+
* @return string
183+
*/
184+
public function getVersionClassname(): string
185+
{
186+
return ucfirst($this->name);
187+
}
188+
181189
/**
182190
* @return \DCarbone\PHPFHIR\Version\Definition
183191
*/

template/core/classes/class_config.php

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
echo "namespace {$namespace};\n\n";
3232
endif;
3333

34-
echo VersionCopyright::getFullPHPFHIRCopyrightComment();
34+
echo $config->getBasePHPFHIRCopyrightComment();
3535

3636
echo "\n\n"; ?>
3737
/**
@@ -43,9 +43,6 @@
4343
*/
4444
class <?php echo PHPFHIR_CLASSNAME_CONFIG; ?> implements \JsonSerializable
4545
{
46-
/** @var bool */
47-
private bool $registerAutoloader = false;
48-
4946
/** @var int */
5047
private int $libxmlOpts;
5148

@@ -61,47 +58,13 @@ class <?php echo PHPFHIR_CLASSNAME_CONFIG; ?> implements \JsonSerializable
6158
*/
6259
public function __construct(array $config = [])
6360
{
64-
foreach(<?php echo PHPFHIR_ENUM_CONFIG_KEY; ?>::values() as $k => $_) {
65-
if (isset($config[$k]) || array_key_exists($k, $config)) {
66-
$this->setKey($k, $config[$k]);
61+
foreach(<?php echo PHPFHIR_ENUM_CONFIG_KEY; ?>::cases() as $key) {
62+
if (isset($config[$key->value]) || array_key_exists($key->value, $config)) {
63+
$this->{"set$key->value"}($config[$key->value);
6764
}
6865
}
6966
}
7067

71-
/**
72-
* Set arbitrary key on this config
73-
*
74-
* @param <?php echo $config->getFullyQualifiedName(true, PHPFHIR_ENUM_CONFIG_KEY); ?>|string $key
75-
* @param mixed $value
76-
* @return static
77-
*/
78-
public function setKey(<?php echo PHPFHIR_ENUM_CONFIG_KEY; ?>|string $key, mixed $value): self
79-
{
80-
if (!is_string($key)) {
81-
$key = $key->value;
82-
}
83-
$this->{'set'.$key}($value);
84-
return $this;
85-
}
86-
87-
/**
88-
* @param bool $registerAutoloader
89-
* @return static
90-
*/
91-
public function setRegisterAutoloader(bool $registerAutoloader): self
92-
{
93-
$this->registerAutoloader = $registerAutoloader;
94-
return $this;
95-
}
96-
97-
/**
98-
* @return bool
99-
*/
100-
public function getRegisterAutoloader(): bool
101-
{
102-
return $this->registerAutoloader;
103-
}
104-
10568
/**
10669
* Sets the option flags to provide to libxml when unserializing XML
10770
*
@@ -171,7 +134,7 @@ public function jsonSerialize(): \stdClass
171134
{
172135
$out = new \stdClass();
173136
foreach(<?php echo PHPFHIR_ENUM_CONFIG_KEY; ?>::cases() as $key) {
174-
$out->{$k} = $this->{$key->getter()}();
137+
$out->{$key->value} = $this->{"get$key->value"}();
175138
}
176139
return $out;
177140
}

template/core/enums/enum_config_key.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
echo "namespace {$namespace};\n\n";
3232
endif;
3333

34-
echo VersionCopyright::getFullPHPFHIRCopyrightComment();
34+
echo $config->getBasePHPFHIRCopyrightComment();
3535

3636
echo "\n\n"; ?>
3737
/**
@@ -43,7 +43,6 @@
4343
*/
4444
enum <?php echo PHPFHIR_ENUM_CONFIG_KEY; ?> : string
4545
{
46-
case REGISTER_AUTOLOADER = 'registerAutoloader';
4746
case LIBXML_OPTS = 'libxmlOpts';
4847
case ROOT_XMLNS = 'rootXmlns';
4948
case OVERRIDE_SOURCE_XMLNS = 'overrideSourceXmlns';

template/core/interfaces/interface_fhir_version.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,62 @@
1616
* limitations under the License.
1717
*/
1818

19+
/** @var \DCarbone\PHPFHIR\Config $config */
20+
21+
$namespace = $config->getFullyQualifiedName(false);
22+
23+
ob_start();
24+
25+
echo "<?php declare(strict_types=1);\n\n";
26+
27+
if ('' !== $namespace) :
28+
echo "namespace {$namespace};\n\n";
29+
endif;
30+
31+
echo $config->getBasePHPFHIRCopyrightComment();
32+
33+
echo "\n\n";
34+
?>
35+
/**
36+
* Interface <?php echo PHPFHIR_INTERFACE_FHIR_VERSION; if ('' !== $namespace) : ?>
37+
38+
* @package \<?php echo $namespace; ?>
39+
<?php endif; ?>
40+
41+
*/
42+
interface <?php echo PHPFHIR_INTERFACE_FHIR_VERSION; ?>
43+
44+
{
45+
/**
46+
* Must return the "name" of this version, e.g. DSTU1, STU3, R5, etc.
47+
* @return string
48+
*/
49+
public function getName(): string;
50+
51+
/**
52+
* Must return the source this version was generated from
53+
* @return string
54+
*/
55+
public function getSourceUrl(): string;
56+
57+
/**
58+
* Must return the date this FHIR version's source was generated
59+
* @return string
60+
*/
61+
public function getFhirGenerationDate(): string;
62+
63+
/**
64+
* Must return config for this version
65+
* @return <?php echo $config->getFullyQualifiedName(true, PHPFHIR_CLASSNAME_CONFIG); ?>
66+
67+
*/
68+
public function getConfig(): <?php echo PHPFHIR_CLASSNAME_CONFIG; ?>;
69+
70+
/**
71+
* Must return the type map class for this version
72+
* @return <?php echo $config->getFullyQualifiedName(true, PHPFHIR_INTERFACE_TYPE_MAP); ?>
73+
74+
*/
75+
public function getTypeMap(): <?php echo PHPFHIR_INTERFACE_TYPE_MAP; ?>;
76+
}
77+
<?php return ob_get_clean();

template/versions/core/classes/class_version.php renamed to template/core/interfaces/interface_response_parser.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818

1919
/** @var \DCarbone\PHPFHIR\Config $config */
20-
/** @var \DCarbone\PHPFHIR\Version $version */
2120

2221
$namespace = $config->getFullyQualifiedName(false);
2322

@@ -29,22 +28,27 @@
2928
echo "namespace {$namespace};\n\n";
3029
endif;
3130

32-
echo $version->getCopyright()->getFullPHPFHIRCopyrightComment();
31+
echo $config->getBasePHPFHIRCopyrightComment();
3332

3433
echo "\n\n";
3534
?>
3635
/**
37-
* Class <?php echo PHPFHIR_CLASSNAME_VERSION; if ('' !== $namespace) : ?>
36+
* Interface <?php echo PHPFHIR_INTERFACE_RESPONSE_PARSER; if ('' !== $namespace) : ?>
3837

3938
* @package \<?php echo $namespace; ?>
4039
<?php endif; ?>
4140

4241
*/
43-
class <?php echo PHPFHIR_CLASSNAME_VERSION; ?>
42+
interface <?php echo PHPFHIR_INTERFACE_RESPONSE_PARSER; ?>
4443

4544
{
46-
public const NAME = '<?php echo $version->getName(); ?>';
47-
public const SOURCE_URL = '<?php echo $version->getSourceUrl(); ?>';
48-
public const FHIR_GENERATION_DATE = '<?php echo $version->getCopyright()->getFHIRGenerationDate(); ?>';
45+
/**
46+
* Must attempt to parse the provided input into FHIR objects.
47+
*
48+
* @param null|string|array|\stdClass|\SimpleXMLElement|\DOMDocument $input
49+
* @return null|<?php echo $config->getFullyQualifiedName(true, PHPFHIR_INTERFACE_TYPE); ?>
50+
51+
* @throws \Exception
52+
*/
53+
public function parse(null|string|array|\stdClass|\SimpleXMLElement|\DOMDocument $input): null|<?php echo PHPFHIR_INTERFACE_TYPE; ?>;
4954
}
50-
<?php return ob_get_clean();
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* Copyright 2024 Daniel Carbone (daniel.p.carbone@gmail.com)
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/** @var \DCarbone\PHPFHIR\Config $config */
20+
21+
$namespace = $config->getFullyQualifiedName(false);
22+
23+
ob_start();
24+
25+
echo "<?php declare(strict_types=1);\n\n";
26+
27+
if ('' !== $namespace) :
28+
echo "namespace {$namespace};\n\n";
29+
endif;
30+
31+
echo $config->getBasePHPFHIRCopyrightComment();
32+
33+
echo "\n\n";
34+
?>
35+
/**
36+
* Interface <?php echo PHPFHIR_INTERFACE_TYPE_MAP; if ('' !== $namespace) : ?>
37+
38+
* @package \<?php echo $namespace; ?>
39+
<?php endif; ?>
40+
41+
*/
42+
interface <?php echo PHPFHIR_INTERFACE_TYPE_MAP; ?>
43+
44+
{
45+
/**
46+
* Must return the fully qualified class name for FHIR Type name. Must return null if type not found
47+
* @param string $typeName
48+
* @return string|null
49+
*/
50+
public function getTypeClass(string $typeName): null|string;
51+
52+
/**
53+
* Must return the full internal class map
54+
* @return array
55+
*/
56+
public function getMap(): array;
57+
58+
/**
59+
* Must return the full list of containable resource types
60+
* @return array
61+
*/
62+
public function getContainableTypes(): array;
63+
64+
/**
65+
* @param string $typeName Name of FHIR object reference by a version's container type
66+
* @return string|null Name of class as string or null if type is not contained in map
67+
*/
68+
public function getContainedTypeClassName(string $typeName): null|string;
69+
70+
/**
71+
* Must attempt to determine if the provided value is or describes a containable resource type
72+
* @param string|array|\SimpleXMLElement|<?php echo PHPFHIR_INTERFACE_TYPE; ?> $type
73+
* @return bool
74+
* @throws \InvalidArgumentException
75+
*/
76+
public function isContainableResource(string|array|\SimpleXMLElement|<?php echo PHPFHIR_INTERFACE_TYPE; ?> $type): bool;
77+
78+
/**
79+
* @param \SimpleXMLElement $node Parent element containing inline resource
80+
* @param <?php echo $config->getFullyQualifiedName(true, PHPFHIR_CLASSNAME_CONFIG); ?> $config
81+
* @return null|<?php echo $config->getfullyQualifiedName(true, PHPFHIR_INTERFACE_CONTAINED_TYPE); ?>
82+
83+
*/
84+
public function getContainedTypeFromXML(\SimpleXMLElement $node, <?php echo PHPFHIR_CLASSNAME_CONFIG; ?> $config): null|<?php echo PHPFHIR_INTERFACE_CONTAINED_TYPE; ?>;
85+
86+
/**
87+
* @param array|null $data
88+
* @return null|<?php echo $config->getfullyQualifiedName(true, PHPFHIR_INTERFACE_CONTAINED_TYPE); ?>
89+
90+
*/
91+
public function getContainedTypeFromArray(null|array $data): null|<?php echo PHPFHIR_INTERFACE_CONTAINED_TYPE; ?>;
92+
}
93+
<?php return ob_get_clean();

0 commit comments

Comments
 (0)