APPNETOS is under active development This website and its documentation are being prepared for public launch. Content and features may change.
Select Theme
Loading

Registry Bootstrap

The Registry Bootstrap initializes the central APPNETOS object registry after runtime class mappings and extensions have been prepared. It establishes the object resolution and lifecycle infrastructure used by subsequent Core and application bootstrap layers.

Purpose and Execution

Registry Bootstrap is step 11 of the APPNETOS bootstrap sequence. It runs after Class Extension Bootstrap and Class Mapping Bootstrap, and before Functions Bootstrap, Core Bootstrap, and Application Runtime Bootstrap.

Its boot() method has one responsibility: initialize Core\Registry.

public function boot(): void
{
    Registry::init();
}

This step does not construct application services, load application data, or perform class mapping itself. Those operations occur when runtime objects are requested later.

Initialization

Registry::init() copies the prepared class extensions and class mappings from RuntimeStateHolder into the Registry's internal state. It also initializes the object history, registered-object store, and shared-instance store.

public static function init(): void
{
    if (self::$initialized) {
        return;
    }

    self::$classExtensions = RuntimeStateHolder::get()->getClassExtensions();
    self::$classMappings = RuntimeStateHolder::get()->getClassMappings();
    self::$objectHistory = [];
    self::$objects = [];
    self::$shared = [];
    self::$initialized = true;
}

The initialization guard prevents a second call from resetting an already initialized Registry. The Registry also provides lazy initialization through ensureInitialized(); the explicit bootstrap establishes the intended initialization point in the startup sequence.

Because the mappings and extensions are copied at initialization, subsequent changes to the RuntimeState do not automatically refresh the Registry's internal resolution tables.

Runtime Class Resolution

The Registry is the runtime entry point for resolving classes prepared by earlier bootstrap layers. It first looks up a Class Mapping for the requested class, then checks for a Class Extension of the mapped class, followed by an extension of the original requested class.

$mappedClass = self::$classMappings[$class] ?? $class;

return self::$classExtensions[$mappedClass] ??
    self::$classExtensions[$class] ??
    $mappedClass;

Use Registry::get() or Registry::getNew() when an object must respect these mappings and extensions. Direct new instantiation does not perform Registry resolution.

The complete configuration and resolution flow is covered in Class Mapping Bootstrap and Class Extension Bootstrap.

Object Lifecycle and Shared Instances

The Registry manages the creation, registration, reuse, replacement, and removal of runtime objects. These operations are available after initialization; they are not performed automatically by the Registry Bootstrap.

Operation Runtime behavior
Registry::get() Returns an existing registered or shared object where available; otherwise creates and registers an instance.
Registry::getNew() Creates a fresh non-shared instance; registration is optional. Shared classes still return their shared instance.
Registry::set() / add() Registers an existing object and records its registration history.
Registry::replace() / rebuild() Replaces or reconstructs a registered runtime object, including related class aliases.
Registry::remove() Removes the registered entries associated with a resolved class family.

Classes annotated with #[Shared] use a single Registry-managed instance within the current runtime lifecycle. The Registry also recognizes the annotation on parent classes. Shared instances are not automatically shared between separate PHP processes or application runtimes.

For long-running runtimes, Registry::clearCollectionDocuments() can clear the in-memory document tracking of existing shared Collections without replacing the Collections, their database connections, or Redis caches.

Property Autowiring

After constructing a new runtime object, the Registry applies APPNETOS property autowiring through Core\Autowire\Base. This occurs after object construction and is distinct from constructor autowiring.

Registry-managed shared instances are also wired when they are first created; returning an already existing instance does not reconstruct it.

Configuration and Dependencies

Registry Bootstrap has no dedicated configuration file, context configuration, or environment-specific override. It consumes the resolution state prepared by the preceding bootstrap layers.

The active application's Class Mapping and Class Extension configuration determines the implementations available to the Registry. The Autoload Bootstrap must make those classes loadable; Registry initialization does not add autoload paths.

Registry Bootstrap belongs to the protected APPNETOS bootstrap chain and is not extendable through the APPNETOS Class Extension system.

Scope of This Bootstrap Step

This page documents initialization and the runtime capabilities it enables. The full Core\Registry API—including typed lookups, registration history, alias handling, and advanced lifecycle operations—belongs in the dedicated Core Registry reference.

No additional diagram is required here: the Class Mapping Bootstrap diagram already illustrates the transition from prepared mappings and extensions to Registry-based runtime resolution.

Next Steps

Previous

Class Mapping

Explore Class Mapping

Next

Functions

Explore Functions