diff --git a/README.md b/README.md index 285a5b60..664d195e 100644 --- a/README.md +++ b/README.md @@ -75,79 +75,22 @@ There are 2 important things to note with this section: ### Generation Example -```php -require __DIR__.'/vendor/autoload.php'; - -$schemaPath = 'schema/path'; +You can view an example config array here: [bin/config.php](./bin/config.php). +```php // first, build new configuration class -$config = new \DCarbone\PHPFHIR\Config([ - // The path to look look for and optionally download source XSD files to - 'schemaPath' => __DIR__ . '/../input', - - // The path to place generated type class files - 'classesPath' => __DIR__ . '/../output', - - // If true, will use a noop null logger - 'silent' => false, - - // If true, will skip generation of test classes - 'skipTests' => false, - - // Map of versions and configurations to generate - // Each entry in this map will grab the latest revision of that particular version. If you wish to use a specific - // version, please see https://www.hl7.org/fhir/directory.html - 'versions' => [ - 'DSTU1' => [ - // Source URL - 'url' => 'https://hl7.org/fhir/DSTU1/fhir-all-xsd.zip', - // Namespace to prefix the generated classes with - 'namespace' => '\\HL7\\FHIR\\DSTU1', - ], - 'DSTU2' => [ - 'url' => 'https://hl7.org/fhir/DSTU2/fhir-all-xsd.zip', - 'namespace' => '\\HL7\\FHIR\\DSTU2', - 'testEndpoint' => 'https://hapi.fhir.org/baseDstu2', - ], - 'STU3' => [ - 'url' => 'https://hl7.org/fhir/STU3/fhir-all-xsd.zip', - 'namespace' => '\\HL7\\FHIR\\STU3', - 'testEndpoint' => 'https://hapi.fhir.org/baseDstu3', - ], - 'R4' => [ - 'url' => 'https://www.hl7.org/fhir/R4/fhir-all-xsd.zip', - 'namespace' => '\\HL7\\FHIR\\R4', - 'testEndpoint' => 'https://hapi.fhir.org/baseR4', - ], - 'R5' => [ - 'url' => 'https://hl7.org/fhir/R5/fhir-all-xsd.zip', - 'namespace' => '\\HL7\\FHIR\\R5', - 'testEndpoint' => 'https://hapi.fhir.org/baseR5', - ] - ], -]); +$config = new \DCarbone\PHPFHIR\Config(require 'config.php'); -// next, build definition class -$version_config = new \DCarbone\PHPFHIR\Config\VersionConfig($config, $config->getVersion('R5')); -$definition = new \DCarbone\PHPFHIR\Definition($version_config); -$definition->buildDefinition(); - -$builder = new \DCarbone\PHPFHIR\Builder($config, $definition); -$builder->render(); +// next, iterate through all configured versions and render code: +foreach ($config->getVersions() as $versionConfig) { + $versionConfig->getDefinition()->getBuilder()->render(); +} ``` -Using the above code will generate class files under the included [output](./output) directory, under the namespace -` HL7\\FHIR\\{version} ` - -If you wish the files to be placed under a different directory, pass the path in as the 2nd argument in the -generator constructor. - -If you wish the classes to have a different base namespace, pass the desired NS name in as the 3rd argument in the -generator constructor. - ## Data Querying -There are a plethora of good HTTP clients you can use to get data out of a FHIR server, so I leave that up to you. +Currently only a very simple client intended for debugging use is generated. A future goal is to generate a more +fully-featured client. ## Response Parsing @@ -166,7 +109,7 @@ require 'path to PHPFHIRResponseParserConfig.php'; require 'path to PHPFHIRResponseParser.php'; // build config -$config = new \YourConfiguredNamespace\PHPFHIRResponseParserConfig([ +$config = new \YourConfiguredNamespace\PHPFHIRConfig([ 'registerAutoloader' => true, // use if you are not using Composer 'libxmlOpts' => LIBXML_NONET | LIBXML_BIGLINES | LIBXML_PARSEHUGE | LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD | LIBXML_NOXMLDECL // choose different libxml arguments if you want, ymmv. 'rootXmlns' => 'https://hl7.org/fhir', // a specific root xmlns to use, if the source does not return one diff --git a/bin/config.php b/bin/config.php index a0937156..39645652 100644 --- a/bin/config.php +++ b/bin/config.php @@ -20,10 +20,10 @@ */ return [ // The path to look look for and optionally download source XSD files to - 'schemaPath' => __DIR__ . '/../input/', + 'schemaPath' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'input/', // The path to place generated type class files - 'classesPath' => __DIR__ . '/../output/', + 'classesPath' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'output/', // If true, will use a noop null logger 'silent' => false, @@ -32,7 +32,7 @@ 'skipTests' => false, // If you wish to specify alternative libxml opts, do so here. - 'libxmlOpts' => LIBXML_NONET | LIBXML_PARSEHUGE | LIBXML_COMPACT, + 'libxmlOpts' => LIBXML_NONET | LIBXML_BIGLINES | LIBXML_PARSEHUGE | LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD | LIBXML_NOXMLDECL, // Map of versions and configurations to generate // Each entry in this map will grab the latest revision of that particular version. If you wish to use a specific @@ -43,6 +43,8 @@ 'url' => 'https://hl7.org/fhir/DSTU1/fhir-all-xsd.zip', // Namespace to prefix the generated classes with 'namespace' => '\\HL7\\FHIR\\DSTU1', + // if defined, enables integration and validation test generation against the provided endpoint. + 'testEndpoint' => '', ], 'DSTU2' => [ 'url' => 'https://hl7.org/fhir/DSTU2/fhir-all-xsd.zip', diff --git a/src/Config.php b/src/Config.php index d54494d7..691d24a2 100644 --- a/src/Config.php +++ b/src/Config.php @@ -19,6 +19,7 @@ */ use DCarbone\PHPFHIR\Config\Version; +use DCarbone\PHPFHIR\Config\VersionConfig; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; @@ -43,7 +44,8 @@ class Config /** @var string */ private string $classesPath = PHPFHIR_DEFAULT_OUTPUT_DIR; - /** @var \DCarbone\PHPFHIR\Config\Version[] */ + + /** @var \DCarbone\PHPFHIR\Config\VersionConfig[] */ private array $versions = []; /** @var bool */ @@ -226,13 +228,13 @@ public function setVersions(array $versions): self { $this->versions = []; foreach ($versions as $name => $version) { - $this->versions[$name] = ($version instanceof Version) ? $version : new Version($name, $version); + $this->versions[$name] = ($version instanceof VersionConfig) ? $version : new VersionConfig($this, new Version($name, $version)); } return $this; } /** - * @return \DCarbone\PHPFHIR\Config\Version[] + * @return \DCarbone\PHPFHIR\Config\VersionConfig[] */ public function getVersions(): array { @@ -250,9 +252,9 @@ public function hasVersion(string $version): bool /** * @param string $version - * @return \DCarbone\PHPFHIR\Config\Version + * @return \DCarbone\PHPFHIR\Config\VersionConfig */ - public function getVersion(string $version): Version + public function getVersion(string $version): VersionConfig { if (!$this->hasVersion($version)) { throw new \OutOfBoundsException( diff --git a/src/Config/VersionConfig.php b/src/Config/VersionConfig.php index 3bba9146..8779d127 100644 --- a/src/Config/VersionConfig.php +++ b/src/Config/VersionConfig.php @@ -19,6 +19,7 @@ */ use DCarbone\PHPFHIR\Config; +use DCarbone\PHPFHIR\Definition; use DCarbone\PHPFHIR\Enum\TestType; use DCarbone\PHPFHIR\Logger; @@ -33,6 +34,9 @@ class VersionConfig /** @var \DCarbone\PHPFHIR\Config\Version */ private Version $version; + /** @var \DCarbone\PHPFHIR\Definition */ + private Definition $definition; + /** * BuildConfig constructor. * @param \DCarbone\PHPFHIR\Config $config @@ -141,4 +145,15 @@ public function getVersion(): Version { return $this->version; } + + /** + * @return \DCarbone\PHPFHIR\Definition + */ + public function getDefinition(): Definition + { + if (!isset($this->definition)) { + $this->definition = new Definition($this); + } + return $this->definition;; + } } \ No newline at end of file diff --git a/src/Definition.php b/src/Definition.php index 856a4e7d..38bd4ed4 100644 --- a/src/Definition.php +++ b/src/Definition.php @@ -35,7 +35,10 @@ class Definition private VersionConfig $config; /** @var \DCarbone\PHPFHIR\Definition\Types|null */ - private ?Types $types = null; + private null|Types $types = null; + + /** @var \DCarbone\PHPFHIR\Builder */ + private Builder $builder; /** * Definition constructor. @@ -132,4 +135,15 @@ public function isDefined(): bool { return null !== $this->getTypes(); } + + /** + * @return \DCarbone\PHPFHIR\Builder + */ + public function getBuilder(): Builder + { + if (!isset($this->builder)) { + $this->builder = new Builder($this->getConfig(), $this); + } + return $this->builder; + } } \ No newline at end of file diff --git a/template/core/classes/class_constants.php b/template/core/classes/class_constants.php index 2a47df38..d23f447e 100644 --- a/template/core/classes/class_constants.php +++ b/template/core/classes/class_constants.php @@ -72,8 +72,6 @@ final class public const UNLIMITED = -1; - public const NOT_SET = ''; - // Validation public const = ''; public const = '';