VOOZH about

URL: https://deepwiki.com/hypervel/foundation/3.1-configuration-system-and-config-provider

⇱ Configuration System and Config Provider | hypervel/foundation | DeepWiki


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

Configuration System and Config Provider

Purpose and Scope

This document details the ConfigProvider class, which serves as Hypervel Foundation's integration point with the Hyperf framework's package discovery system. The ConfigProvider declares dependencies, listeners, commands, and publishable assets that are automatically registered during application bootstrap.

For information about how the bootstrap process discovers and registers service providers, see Bootstrap Process and Service Registration. For details on core service configuration, see Foundation Service Provider.

ConfigProvider Overview

The ConfigProvider class implements Hyperf's standard configuration provider interface, which allows packages to declare their framework integrations declaratively. When Hyperf's bootstrap system scans installed Composer packages, it looks for classes named ConfigProvider and invokes them to gather package metadata.

The ConfigProvider returns a structured array containing four key sections:

SectionPurpose
dependenciesContainer bindings and interface-to-implementation mappings
listenersEvent listeners to register with the event dispatcher
commandsConsole commands to register with the Artisan application
publishFiles or directories that can be published to the application

Sources: src/ConfigProvider.php18-47

ConfigProvider Structure Diagram


Sources: src/ConfigProvider.php20-46

Dependency Registration

The dependencies array defines container bindings that replace or extend Hyperf's default implementations. These bindings are registered in the application's dependency injection container during the bootstrap process.

Registered Dependencies

Interface/ClassImplementationPurpose
ApplicationInterfaceApplicationFactoryReplaces Hyperf's console application with Hypervel's enhanced Artisan application
InitProcessTitleListenerSetProcessTitleOverrides Hyperf's process title listener to use Hypervel's implementation

The ApplicationInterface binding is particularly important as it ensures that console command execution uses Hypervel's ApplicationFactory, which provides Laravel-style Artisan functionality with enhanced command discovery and registration capabilities.

Sources: src/ConfigProvider.php23-26

Dependency Registration Flow


Sources: src/ConfigProvider.php23-26

Listener Registration

The listeners array declares event listeners that should be registered with Hyperf's event dispatcher. These listeners respond to framework lifecycle events and system signals.

Registered Listeners

Listener ClassPurpose
ErrorExceptionHandlerConverts PHP errors to exceptions for consistent error handling
ReloadDotenvAndConfigReloads environment variables and configuration when server workers are gracefully reloaded

The ErrorExceptionHandler is a Hyperf core listener that ensures all PHP errors are converted to exceptions, enabling consistent exception handling across the application.

The ReloadDotenvAndConfig listener responds to worker reload signals (triggered by commands like server:reload), ensuring that environment variables and configuration are refreshed without requiring a full server restart.

Sources: src/ConfigProvider.php27-30

Listener Event Flow


Sources: src/ConfigProvider.php27-30

Command Registration

The commands array declares console commands that should be available through Hypervel's Artisan CLI. These commands are automatically discovered and registered with the console application during bootstrap.

Registered Commands

Command ClassSignaturePurpose
AboutCommandaboutDisplays information about the application, environment, and installed packages
ConfigShowCommandconfig:showDisplays configuration values for debugging and inspection
ServerReloadCommandserver:reloadGracefully reloads Swoole server workers without downtime
VendorPublishCommandvendor:publishPublishes package assets (configs, views, etc.) to the application

These commands provide essential development and operations utilities. The server:reload command is particularly important in development, as it allows code changes to take effect without restarting the entire server.

Sources: src/ConfigProvider.php31-36

ServerReloadCommand Implementation

The ServerReloadCommand demonstrates how commands interact with the configuration system and application services:


Sources: src/Console/Commands/ServerReloadCommand.php28-70

The command retrieves the server's PID file path from configuration at src/Console/Commands/ServerReloadCommand.php30 reads the PID from the filesystem at src/Console/Commands/ServerReloadCommand.php41 and sends POSIX signals to trigger graceful worker reloads at src/Console/Commands/ServerReloadCommand.php45 and src/Console/Commands/ServerReloadCommand.php58

Publishable Assets

The publish array defines files or directories that can be copied from the package to the application using the vendor:publish command. This mechanism allows applications to customize package configurations by publishing them to the local codebase.

Published Configuration File

PropertyValueDescription
idconfigIdentifier used with --id=config flag in vendor:publish command
description"The configuration file of foundation."Human-readable description of the asset
source__DIR__ . '/../publish/app.php'Source path within the package
destinationBASE_PATH . '/config/autoload/app.php'Destination path in the application

The published app.php configuration file contains application-level settings such as:

  • Application name, environment, and timezone
  • Debug mode settings
  • Service provider declarations
  • Class alias definitions (facades)
  • Middleware configuration

Sources: src/ConfigProvider.php37-44

Publishing Flow


Sources: src/ConfigProvider.php37-44

Integration with Hyperf Bootstrap

The ConfigProvider integrates with Hyperf's package discovery mechanism, which scans Composer's installed packages for configuration providers. This integration happens automatically during the application bootstrap process.

Discovery and Registration Process


Sources: src/ConfigProvider.php18-47

Composer Integration

Hypervel Foundation declares its ConfigProvider in composer.json under the extra.hyperf.config key. Hyperf's bootstrap system reads this declaration and automatically invokes the ConfigProvider during application initialization, before any service providers are registered.

The ConfigProvider pattern enables packages to:

  1. Declare dependencies without requiring manual container registration
  2. Register listeners without modifying the event dispatcher configuration
  3. Provide commands without editing the console kernel
  4. Offer publishable assets that applications can optionally customize

This declarative approach separates package metadata from application configuration, allowing packages to be self-contained and easily integrated into any Hypervel application.

Sources: src/ConfigProvider.php18-47

Configuration Values and Environment

While the ConfigProvider defines what gets registered, the actual configuration values come from multiple sources:

SourcePriorityPurpose
Environment variables (.env)HighestRuntime-specific values (database credentials, API keys)
Configuration files (config/*)MediumApplication settings and feature flags
Package defaultsLowestFallback values provided by packages

The ReloadDotenvAndConfig listener ensures that configuration remains fresh during development by reloading these sources when workers are gracefully reloaded through the server:reload command.

Sources: src/ConfigProvider.php29

Summary

The ConfigProvider class serves as Hypervel Foundation's integration point with Hyperf's package system:

  • Dependencies: Replaces core Hyperf services with Hypervel implementations
  • Listeners: Registers event handlers for error conversion and configuration reloading
  • Commands: Provides essential development and operations commands
  • Publish: Makes configuration files available for application customization

This declarative configuration mechanism allows Hypervel Foundation to extend Hyperf transparently while maintaining clean separation between package metadata and application configuration.

Sources: src/ConfigProvider.php18-47