Skip to content

Commit

Permalink
xmlns improvements, template file hierarchy improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dcarbone committed Apr 22, 2024
1 parent 0070f93 commit 5dfdc26
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 23 deletions.
11 changes: 8 additions & 3 deletions files/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@
const PHPFHIR_DOCBLOC_MAX_LENGTH = 80;
const PHPFHIR_NAMESPACE_TRIM_CUTSET = " \t\n\r\0\x0b\\/";
define('PHPFHIR_TEMPLATE_DIR', realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'template'));
const PHPFHIR_TEMPLATE_INTERFACES_DIR = PHPFHIR_TEMPLATE_DIR . DIRECTORY_SEPARATOR . 'interfaces';
const PHPFHIR_TEMPLATE_TRAITS_DIR = PHPFHIR_TEMPLATE_DIR . DIRECTORY_SEPARATOR . 'traits';

// "file" directory. will move at some point.
const PHPFHIR_TEMPLATE_FILE_DIR = PHPFHIR_TEMPLATE_DIR . DIRECTORY_SEPARATOR . 'file';
const PHPFHIR_TEMPLATE_UTILITIES_DIR = PHPFHIR_TEMPLATE_DIR . DIRECTORY_SEPARATOR . 'utilities';

// Core interfaces, traits, and classes
const PHPFHIR_TEMPLATE_CORE_DIR = PHPFHIR_TEMPLATE_DIR . DIRECTORY_SEPARATOR . 'core';
const PHPFHIR_TEMPLATE_CORE_INTERFACES_DIR = PHPFHIR_TEMPLATE_CORE_DIR . DIRECTORY_SEPARATOR . 'interfaces';
const PHPFHIR_TEMPLATE_CORE_TRAITS_DIR = PHPFHIR_TEMPLATE_CORE_DIR . DIRECTORY_SEPARATOR . 'traits';
const PHPFHIR_TEMPLATE_CORE_CLASSES_DIR = PHPFHIR_TEMPLATE_CORE_DIR . DIRECTORY_SEPARATOR . 'classes';

// Type rendering
const PHPFHIR_TEMPLATE_TYPES_DIR = PHPFHIR_TEMPLATE_DIR . DIRECTORY_SEPARATOR . 'types';
Expand Down
6 changes: 3 additions & 3 deletions files/funcs.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
<?php declare(strict_types=1);

/*
* Copyright 2016-2022 Daniel Carbone ([email protected])
* Copyright 2016-2024 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.
Expand All @@ -25,7 +25,7 @@
* @param array $vars
* @return mixed
*/
function require_with(string $requiredFile, array $vars)
function require_with(string $requiredFile, array $vars): mixed
{
$num = extract($vars, EXTR_OVERWRITE);
if ($num !== count($vars)) {
Expand Down
26 changes: 13 additions & 13 deletions src/Render/Templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ abstract class Templates
*/
public static function renderPhpFhirTypeInterface(VersionConfig $config, Types $types): string
{
return require PHPFHIR_TEMPLATE_INTERFACES_DIR . DIRECTORY_SEPARATOR . 'phpfhir_type.php';
return require PHPFHIR_TEMPLATE_CORE_INTERFACES_DIR . DIRECTORY_SEPARATOR . 'interface_type.php';
}

/**
Expand All @@ -45,7 +45,7 @@ public static function renderPhpFhirTypeInterface(VersionConfig $config, Types $
*/
public static function renderPhpFhirXmlSerializableInterface(VersionConfig $config, Types $types): string
{
return require PHPFHIR_TEMPLATE_INTERFACES_DIR . DIRECTORY_SEPARATOR . 'phpfhir_xml_serializable.php';
return require PHPFHIR_TEMPLATE_CORE_INTERFACES_DIR . DIRECTORY_SEPARATOR . 'interface_xml_serializable.php';
}

/**
Expand All @@ -55,7 +55,7 @@ public static function renderPhpFhirXmlSerializableInterface(VersionConfig $conf
*/
public static function renderPhpFhirCommentContainerInterface(VersionConfig $config, Types $types): string
{
return require PHPFHIR_TEMPLATE_INTERFACES_DIR . DIRECTORY_SEPARATOR .'phpfhir_comment_container.php';
return require PHPFHIR_TEMPLATE_CORE_INTERFACES_DIR . DIRECTORY_SEPARATOR .'interface_comment_container.php';
}

/**
Expand All @@ -65,7 +65,7 @@ public static function renderPhpFhirCommentContainerInterface(VersionConfig $con
*/
public static function renderPhpFhirCommentContainerTrait(VersionConfig $config, Types $types): string
{
return require PHPFHIR_TEMPLATE_TRAITS_DIR . DIRECTORY_SEPARATOR . 'phpfhir_comment_container.php';
return require PHPFHIR_TEMPLATE_CORE_TRAITS_DIR . DIRECTORY_SEPARATOR . 'trait_comment_container.php';
}

/**
Expand All @@ -75,7 +75,7 @@ public static function renderPhpFhirCommentContainerTrait(VersionConfig $config,
*/
public static function renderPhpFhirValidationAssertionsTrait(VersionConfig $config, Types $types): string
{
return require PHPFHIR_TEMPLATE_TRAITS_DIR . DIRECTORY_SEPARATOR .'phpfhir_validation_assertions.php';
return require PHPFHIR_TEMPLATE_CORE_TRAITS_DIR . DIRECTORY_SEPARATOR .'trait_validation_assertions.php';
}

/**
Expand All @@ -85,12 +85,12 @@ public static function renderPhpFhirValidationAssertionsTrait(VersionConfig $con
*/
public static function renderPhpFhirChangeTrackingTrait(VersionConfig $config, Types $types): string
{
return require PHPFHIR_TEMPLATE_TRAITS_DIR . DIRECTORY_SEPARATOR . 'phpfhir_change_tracking.php';
return require PHPFHIR_TEMPLATE_CORE_TRAITS_DIR . DIRECTORY_SEPARATOR . 'trait_change_tracking.php';
}

public static function renderPhpFhirXhtmlNamespaceTrait(VersionConfig $config, Types $types): string
{
return require PHPFHIR_TEMPLATE_TRAITS_DIR . DIRECTORY_SEPARATOR . 'phpfhir_xml_namespace.php';
return require PHPFHIR_TEMPLATE_CORE_TRAITS_DIR . DIRECTORY_SEPARATOR . 'trait_xml_namespace.php';
}

/**
Expand All @@ -100,7 +100,7 @@ public static function renderPhpFhirXhtmlNamespaceTrait(VersionConfig $config, T
*/
public static function renderPhpFhirContainedTypeInterface(VersionConfig $config, Types $types): string
{
return require PHPFHIR_TEMPLATE_INTERFACES_DIR . DIRECTORY_SEPARATOR . 'phpfhir_contained_type.php';
return require PHPFHIR_TEMPLATE_CORE_INTERFACES_DIR . DIRECTORY_SEPARATOR . 'interface_contained_type.php';
}

/**
Expand All @@ -110,7 +110,7 @@ public static function renderPhpFhirContainedTypeInterface(VersionConfig $config
*/
public static function renderPhpFhirResponseParserConfigClass(VersionConfig $config, Types $types): string
{
return require PHPFHIR_TEMPLATE_UTILITIES_DIR . DIRECTORY_SEPARATOR .'class_response_parser_config.php';
return require PHPFHIR_TEMPLATE_CORE_CLASSES_DIR . DIRECTORY_SEPARATOR .'class_response_parser_config.php';
}

/**
Expand All @@ -120,7 +120,7 @@ public static function renderPhpFhirResponseParserConfigClass(VersionConfig $con
*/
public static function renderPhpFhirResponseParserClass(VersionConfig $config, Types $types): string
{
return require PHPFHIR_TEMPLATE_UTILITIES_DIR . DIRECTORY_SEPARATOR .'class_response_parser.php';
return require PHPFHIR_TEMPLATE_CORE_CLASSES_DIR . DIRECTORY_SEPARATOR .'class_response_parser.php';
}

/**
Expand Down Expand Up @@ -152,7 +152,7 @@ public static function renderXhtmlTypeClass(VersionConfig $config, Types $types,
*/
public static function renderConstants(VersionConfig $config, Types $types): string
{
return require PHPFHIR_TEMPLATE_UTILITIES_DIR . DIRECTORY_SEPARATOR .'class_constants.php';
return require PHPFHIR_TEMPLATE_CORE_CLASSES_DIR . DIRECTORY_SEPARATOR .'class_constants.php';
}

/**
Expand All @@ -162,7 +162,7 @@ public static function renderConstants(VersionConfig $config, Types $types): str
*/
public static function renderTypeMapClass(VersionConfig $config, Types $types): string
{
return require PHPFHIR_TEMPLATE_UTILITIES_DIR . DIRECTORY_SEPARATOR . 'class_typemap.php';
return require PHPFHIR_TEMPLATE_CORE_CLASSES_DIR . DIRECTORY_SEPARATOR . 'class_typemap.php';
}

/**
Expand All @@ -172,7 +172,7 @@ public static function renderTypeMapClass(VersionConfig $config, Types $types):
*/
public static function renderAutoloaderClass(VersionConfig $config, Types $types): string
{
return require PHPFHIR_TEMPLATE_UTILITIES_DIR . DIRECTORY_SEPARATOR . 'class_autoloader.php';
return require PHPFHIR_TEMPLATE_CORE_CLASSES_DIR . DIRECTORY_SEPARATOR . 'class_autoloader.php';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
if (!interface_exists('\<?php echo $nsPrefix . PHPFHIR_INTERFACE_COMMENT_CONTAINER; ?>', false)) {
require __DIR__ . DIRECTORY_SEPARATOR . '<?php echo PHPFHIR_INTERFACE_COMMENT_CONTAINER; ?>.php';
}
if (!interface_exists('\<?php echo $nsPrefix . PHPFHIR_INTERFACE_XML_SERIALIZABLE; ?>', false)) {
require __DIR__ . DIRECTORY_SEPARATOR . '<?php echo PHPFHIR_INTERFACE_XML_SERIALIZABLE; ?>.php';
}

// traits
if (!trait_exists('\<?php echo $nsPrefix . PHPFHIR_TRAIT_COMMENT_CONTAINER; ?>', false)) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
<?php endif; ?>

*/
trait <?php echo PHPFHIR_TRAIT_XMLNS; ?>
trait <?php echo PHPFHIR_TRAIT_XMLNS; ?>

{
/** @var string */
protected string $_xmlns = '';

/**
* @param null|string $xmlNamespace
* @return self
* @return static
*/
public function _setFHIRXMLNamespace(null|string $xmlNamespace): self
{
Expand All @@ -65,10 +65,15 @@ public function _getFHIRXMLNamespace(): string
}

/**
* @param string $elementName Name to use for the element
* @return string
* @throws \InvalidArgumentException
*/
public function _getFHIRXMLElementDefinition(string $elementName): string
{
if ('' === $elementName) {
throw new \InvalidArgumentException(sprintf('%s::_getFHIRXMLElementDefinition - $elementName is required', get_called_class()));
}
$xmlns = $this->_getFHIRXMLNamespace();
if ('' !== $xmlns) {
$xmlns = sprintf(' xmlns="%s"', $xmlns);
Expand Down
2 changes: 1 addition & 1 deletion template/file/header_type.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
echo "<?php declare(strict_types=1);\n\n";

if ('' !== $namespace) {
echo "namespace {$namespace};\n\n";
echo sprintf("namespace %s;\n\n", $namespace);
}

// print out huge copyright block
Expand Down
2 changes: 1 addition & 1 deletion template/types/serialization/xml/unserialize/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static function xmlUnserialize(null|string|\DOMElement $element, null|<?p
));
}
<?php endif; ?>
if ('' === $type->_getFHIRXMLNamespace() && (null === $element->parentNode || $element->namespaceURI !== $element->parentNode->namespaceURI)) {
if ('' === $type->_getFHIRXMLNamespace() && $element->namespaceURI) {
$type->_setFHIRXMLNamespace($element->namespaceURI);
}
<?php return ob_get_clean();

0 comments on commit 5dfdc26

Please sign in to comment.