-
-
Notifications
You must be signed in to change notification settings - Fork 11
Autoloading
This library supports two autoloading strategies: Composer's PSR-4 autoloader, and a built-in autoloader for standalone usage.
When installed via Composer, the library's PSR-4 namespace mapping is registered automatically. Simply require Composer's autoloader as usual:
<?php
require __DIR__ . '/vendor/autoload.php';No additional configuration is needed — all classes under DCarbone\PHPFHIRGenerated\ are resolved automatically.
If you are not using Composer, require the library's built-in autoloader:
<?php
require __DIR__ . '/path/to/src/DCarbone/PHPFHIRGenerated/Autoloader.php';This immediately registers the autoloader via spl_autoload_register().
The Autoloader class uses a two-tier strategy:
Shared (non-version-specific) classes — interfaces, traits, encoding, validation, and client classes — are mapped in a static class map. When one of these classes is requested, it is loaded directly from the map.
Core classes include:
DCarbone\PHPFHIRGenerated\ConstantsDCarbone\PHPFHIRGenerated\FHIRVersionDCarbone\PHPFHIRGenerated\Client\*DCarbone\PHPFHIRGenerated\Encoding\*DCarbone\PHPFHIRGenerated\Types\*DCarbone\PHPFHIRGenerated\Validation\*DCarbone\PHPFHIRGenerated\Versions\VersionConfigDCarbone\PHPFHIRGenerated\Versions\VersionInterface- etc.
Each FHIR version (DSTU1, DSTU2, STU3, R4, R4B, R5) has its own autoloader class. Version autoloaders are registered lazily — they are only loaded and registered when a class from that version's namespace is first requested.
This means:
- If your application only uses R4 types, only the R4 autoloader will be activated.
- The DSTU1, DSTU2, STU3, R4B, and R5 autoloaders will never be loaded, saving memory and startup time.
The built-in autoloader registers itself as soon as Autoloader.php is required:
// At the bottom of Autoloader.php:
Autoloader::register();You can also manually unregister it if needed:
<?php
use DCarbone\PHPFHIRGenerated\Autoloader;
Autoloader::unregister();If you are using Composer but also want the built-in autoloader (e.g., during development), both can coexist. Composer's autoloader will typically resolve classes first. The built-in autoloader acts as a fallback.