VOOZH about

URL: https://deepwiki.com/hypervel/components/2.1-application-container-and-lifecycle

⇱ Application Container and Lifecycle | hypervel/components | DeepWiki


Loading...
Last indexed: 7 March 2026 (96fbab)
Menu

Application Container and Lifecycle

Purpose and Scope

This document describes the Application class, which serves as the central container and lifecycle manager for the Hypervel framework. The Application class extends Hyperf's dependency injection container while providing Laravel-compatible bootstrapping, service provider management, and path resolution.

For information about the bootstrapping process and service provider registration flow, see Service Providers and Bootstrapping. For configuration management details, see Configuration Management.


Application Class Architecture

The Application class is the foundation of a Hypervel application. It combines dependency injection container functionality with application lifecycle management.

Class Hierarchy


Sources: src/foundation/src/Application.php25-89 src/foundation/src/Contracts/Application.php1-207


Application Construction and Initialization

Constructor Flow

The Application constructor initializes the container and establishes the base application structure:


Sources: src/foundation/src/Application.php82-95

Base Bindings

The application registers itself as the container instance:

Abstract TypeConcrete Instance
ContainerInterface::class$this (Application instance)

This allows the application to be resolved from the container as the container itself.

Sources: src/foundation/src/Application.php108-111


Core Container Aliases

The application registers extensive container aliases to provide flexible service resolution. This allows developers to access services through multiple abstract names.

Alias Mapping Structure


Key Service Aliases

Service CategoryPrimary AbstractCommon Aliases
ContainerPsr\Container\ContainerInterfaceapp, Hyperf\Di\Container, Hypervel\Container\Container
ConfigHyperf\Contract\ConfigInterfaceconfig, Hypervel\Config\Contracts\Repository
EventsPsr\EventDispatcher\EventDispatcherInterfaceevents, Hypervel\Event\Contracts\Dispatcher
RequestPsr\Http\Message\ServerRequestInterfacerequest, Hyperf\HttpServer\Request
ResponseHypervel\Http\Contracts\ResponseContractresponse, Hyperf\HttpServer\Response
CacheHypervel\Cache\Contracts\Factorycache, Hypervel\Cache\CacheManager
DatabaseHyperf\DbConnection\Dbdb
ViewHypervel\View\Contracts\Factoryview
RouterHypervel\Router\Routerrouter
URL GeneratorHypervel\Router\Contracts\UrlGeneratorurl

Sources: src/foundation/src/Application.php546-664


Bootstrapping Process

The bootstrapping process prepares the application for handling requests by loading configuration, registering providers, and initializing services.

Bootstrap Lifecycle


Sources: src/foundation/src/Application.php118-129

Bootstrap State Tracking

The application tracks whether it has been bootstrapped:


Sources: src/foundation/src/Application.php44-153

Bootstrap Callbacks

The application provides hooks for executing code before or after specific bootstrappers:

MethodPurposeEvent Name Pattern
beforeBootstrapping()Register callback before bootstrapper"bootstrapping: " . $bootstrapper
afterBootstrapping()Register callback after bootstrapper"bootstrapped: " . $bootstrapper

Sources: src/foundation/src/Application.php134-145


Service Provider Management

Service providers are the primary mechanism for registering services and bootstrapping application components.

Provider Registration Flow


Sources: src/foundation/src/Application.php311-345

Provider Storage

The application maintains two tracking arrays:

ArrayPurposeType
$serviceProvidersStores provider instancesarray<string, ServiceProvider>
$loadedProvidersTracks loaded provider class namesarray<string, bool>

Sources: src/foundation/src/Application.php66-385

Provider Resolution


Sources: src/foundation/src/Application.php370-373


Application Boot Process

The boot process activates all registered service providers and executes boot callbacks.

Boot State Machine


Sources: src/foundation/src/Application.php398-416

Provider Boot Sequence

Each service provider is booted individually with its own callback lifecycle:


Sources: src/foundation/src/Application.php421-430

Boot Callbacks

The application supports callbacks at two boot lifecycle points:

Callback TypeRegistration MethodExecution Timing
Bootingbooting(callable $callback)Before any provider boots
Bootedbooted(callable $callback)After all providers boot

Note: If a booted callback is registered after the application has already booted, it executes immediately.

Sources: src/foundation/src/Application.php435-466


Path Resolution

The application provides convenient methods for resolving paths to standard application directories.

Path Helper Methods


Path Resolution Table

MethodDefault DirectoryConfigurable?Example Usage
basePath()/Yes (constructor)$app->basePath('bootstrap')
path()app/No$app->path('Models')
configPath()config/No$app->configPath('app.php')
databasePath()database/No$app->databasePath('migrations')
langPath()lang/No$app->langPath('en')
publicPath()public/No$app->publicPath('index.php')
resourcePath()resources/No$app->resourcePath('views')
viewPath()resources/viewsYes (config)$app->viewPath('layouts')
storagePath()storage/No$app->storagePath('logs')

Sources: src/foundation/src/Application.php160-244

View Path Configuration

The viewPath() method is unique in that it reads from configuration:


Sources: src/foundation/src/Application.php228-236

Path Joining

All path methods use the joinPaths() helper for cross-platform path concatenation:

Sources: src/foundation/src/Application.php249-252


Environment Detection

The application provides methods to detect and check the current environment.

Environment Methods


Sources: src/foundation/src/Application.php259-306

Environment Check Examples

MethodPurposeTypical Return Value
environment()Get current environment"local", "production", "testing"
environment('local', 'staging')Check if in local or stagingtrue or false
isLocal()Check if in local environmenttrue or false
isProduction()Check if in productiontrue or false
runningUnitTests()Check if environment is testingtrue or false
hasDebugModeEnabled()Check debug modetrue or false

Sources: src/foundation/src/Application.php259-306


Locale Management

The application delegates locale management to the translator service while providing convenient access methods.

Locale Operations


Sources: src/foundation/src/Application.php504-541

Locale Methods

MethodPurposeRelated Event
getLocale()Get current localeNone
currentLocale()Alias for getLocale()None
getFallbackLocale()Get fallback localeNone
isLocale(string $locale)Check if locale matchesNone
setLocale(string $locale)Set current localeLocaleUpdated

Sources: src/foundation/src/Application.php504-541


Additional Utilities

Application Version

The application provides version information through a constant:


Sources: src/foundation/src/Application.php34

HTTP Exception Helpers

The abort() method provides a convenient way to throw HTTP exceptions:


Sources: src/foundation/src/Application.php474-481

Namespace Detection

The application can detect the application namespace from composer.json:


Sources: src/foundation/src/Application.php671-687


Usage Examples

Basic Application Initialization


Service Provider Registration


Bootstrap Hooks


Sources: src/foundation/src/Application.php134-450

Refresh this wiki

On this page