VOOZH about

URL: https://deepwiki.com/hypervel/foundation/3.2-bootstrap-process-and-service-registration

⇱ Bootstrap Process and Service Registration | hypervel/foundation | DeepWiki


Loading...
Last indexed: 7 February 2026 (101eff)
Menu

Bootstrap Process and Service Registration

Purpose and Scope

This document explains the bootstrap pipeline that initializes the Hypervel application, focusing on two critical bootstrappers: RegisterProviders and RegisterFacades. It covers how service providers are discovered from Composer packages and application configuration, how packages can be filtered from discovery, and how facades (class aliases) are registered to provide convenient static access to framework services.

For information about the Application container and its lifecycle, see Application Container and Dependency Injection. For details on the FoundationServiceProvider's role in establishing core services, see Foundation Service Provider. For configuration system details, see Configuration System and Config Provider.


Bootstrap Pipeline Overview

The application bootstrap process consists of a sequence of bootstrappers that configure and initialize the framework. Two key bootstrappers in this sequence are responsible for service registration and facade setup:

BootstrapperPurposePrimary Responsibility
RegisterProvidersService Provider RegistrationDiscovers providers from Composer packages and configuration, filters based on dont-discover rules, registers them with the application container
RegisterFacadesFacade/Alias RegistrationCreates class aliases from Composer and configuration sources, enabling static facade access

These bootstrappers are invoked during application initialization, before the application is fully booted. They populate the service container with providers and establish the facade system that developers use throughout the application.

Diagram: Bootstrap Pipeline and Bootstrapper Sequence


Sources: src/Bootstrap/RegisterProviders.php19-54 src/Bootstrap/RegisterFacades.php19-35


Service Provider Discovery and Registration

The RegisterProviders bootstrapper implements a sophisticated discovery mechanism that aggregates service providers from multiple sources and applies filtering rules before registering them with the application container.

Provider Discovery from Composer Packages

The discovery process begins by examining Composer package metadata. Each installed package can declare service providers in its composer.json file under extra.hypervel.providers:


The RegisterProviders::bootstrap() method uses Composer::getMergedExtra() to aggregate all provider declarations across all installed packages. This returns an array where each key is a package name and each value contains the package's extra configuration.

Diagram: Provider Discovery Flow


Sources: src/Bootstrap/RegisterProviders.php25-28

Filtering with dont-discover

The framework supports a dont-discover mechanism that allows packages and applications to exclude specific packages from automatic provider registration. This is useful when you want to manually register a provider or when a package's automatic registration conflicts with application requirements.

The filtering process aggregates dont-discover rules from two sources:

  1. Package-level dont-discover: Defined in any package's composer.json under extra.hypervel.dont-discover
  2. Project-level dont-discover: Defined in the root composer.json under extra.hypervel.dont-discover

The special value ['*'] in the dont-discover array disables all automatic provider discovery from packages, requiring manual provider registration.

Code Mapping: dont-discover Implementation

MethodLocationResponsibility
packagesToIgnore()src/Bootstrap/RegisterProviders.php56-67Aggregates dont-discover rules from packages and project
Provider filteringsrc/Bootstrap/RegisterProviders.php24-35Checks each package against ignore list, excludes matching providers

The filtering logic at src/Bootstrap/RegisterProviders.php29-33 uses array_filter() with ARRAY_FILTER_USE_KEY to exclude packages whose names appear in the packagesToIgnore() array.

Sources: src/Bootstrap/RegisterProviders.php22-35 src/Bootstrap/RegisterProviders.php56-67

Configuration-based Providers

In addition to Composer-based discovery, the application can explicitly declare providers in its configuration file. The config/app.php file (or its published equivalent) contains a providers array:


These configuration-based providers are merged with Composer-discovered providers at src/Bootstrap/RegisterProviders.php37-42 The array_unique() call ensures that if a provider appears in both Composer metadata and configuration, it's only registered once.

Sources: src/Bootstrap/RegisterProviders.php37-42

FoundationServiceProvider Priority

The FoundationServiceProvider is a critical infrastructure provider that must be registered before other providers to ensure core services are available. The RegisterProviders bootstrapper enforces this priority by searching for FoundationServiceProvider in the provider list and moving it to the first position if found:


This prioritization happens at src/Bootstrap/RegisterProviders.php44-49 after all providers have been discovered and deduplicated but before registration occurs.

Sources: src/Bootstrap/RegisterProviders.php44-49

Registration Process

After discovery, filtering, merging, and prioritization, the final provider list is registered with the application container. The registration loop at src/Bootstrap/RegisterProviders.php51-53 calls $app->register() for each provider class:


The register() method on the Application container instantiates the provider and calls its register() method, allowing it to bind services into the container. Provider booting occurs later in the application lifecycle.

Diagram: Complete Provider Registration Pipeline


Sources: src/Bootstrap/RegisterProviders.php19-54


Facade and Class Alias Registration

The RegisterFacades bootstrapper establishes the facade system by creating class aliases that map short, convenient names to actual facade classes. This enables static access to framework services through a clean API.

Clearing Resolved Instances

Before registering any aliases, the bootstrapper clears all resolved facade instances by calling Facade::clearResolvedInstances() at src/Bootstrap/RegisterFacades.php21 This ensures that facades resolve fresh instances from the newly bootstrapped container, preventing stale references from previous bootstrap cycles (relevant in testing contexts or when refreshing the application).

Sources: src/Bootstrap/RegisterFacades.php21

Alias Sources

Class aliases are aggregated from two sources, similar to provider discovery:

  1. Composer Aliases: Defined in the root composer.json under extra.hypervel.aliases
  2. Configuration Aliases: Defined in config/app.php under the aliases key

The bootstrapper attempts to load Composer aliases at src/Bootstrap/RegisterFacades.php24-28 wrapping the operation in a try-catch to gracefully handle missing configuration. Configuration aliases are loaded at src/Bootstrap/RegisterFacades.php30-31

The two sources are merged at src/Bootstrap/RegisterFacades.php32 with configuration aliases taking precedence if there are conflicts (since they appear later in the merge).

Example Configuration Structures:

Composer aliases (composer.json):


Configuration aliases (config/app.php):


Sources: src/Bootstrap/RegisterFacades.php23-32

Registration Mechanism

The registerAliases() method at src/Bootstrap/RegisterFacades.php37-46 performs the actual alias registration using PHP's class_alias() function:


Key Implementation Details:

AspectImplementationLocation
Pre-checkSkip if alias already exists as a classsrc/Bootstrap/RegisterFacades.php40-42
RegistrationUse class_alias($class, $alias)src/Bootstrap/RegisterFacades.php44
OrderProcess all Composer aliases, then all config aliasessrc/Bootstrap/RegisterFacades.php32

The pre-check at src/Bootstrap/RegisterFacades.php40-42 prevents attempting to alias over existing classes, which would cause a fatal error. This allows the application to define custom implementations that take precedence over framework-provided facades.

Diagram: Facade Registration Flow


Sources: src/Bootstrap/RegisterFacades.php19-46


Integration with Application Lifecycle

The bootstrap process integrates with the broader application lifecycle as follows:

  1. Application Construction: The Application container is instantiated
  2. Bootstrap Execution: RegisterProviders and RegisterFacades are invoked
  3. Provider Booting: After registration, all providers are booted in sequence
  4. Request Handling: The fully initialized application handles HTTP or console requests

The separation between provider registration (during bootstrap) and provider booting (after bootstrap) allows providers to assume that all services have been registered before any are booted, enabling proper dependency resolution.

Key Classes and Methods:

ClassMethodPurpose
RegisterProvidersbootstrap(ApplicationContract)Discovers and registers service providers
RegisterProviderspackagesToIgnore()Determines which packages to exclude from discovery
RegisterFacadesbootstrap(ApplicationContract)Registers class aliases for facades
RegisterFacadesregisterAliases(array)Creates individual class aliases using class_alias()
ComposergetMergedExtra()Aggregates extra configuration from all packages
ComposergetJsonContent()Retrieves root composer.json content

Sources: src/Bootstrap/RegisterProviders.php14-68 src/Bootstrap/RegisterFacades.php14-47