VOOZH about

URL: https://deepwiki.com/hypervel/config/1-overview

⇱ hypervel/config | DeepWiki


Loading...
Menu

Overview

The hypervel/config package is a configuration management library for Hypervel/Hyperf applications. It provides automatic configuration discovery from Composer packages, sophisticated configuration merging strategies, type-safe configuration access, and seamless integration with Hyperf's dependency injection system.


Package Identity

The hypervel/config package is a configuration management library for the Hypervel framework. It extends and integrates with Hyperf's configuration system while providing additional functionality for automatic configuration discovery and sophisticated merging strategies.

PropertyValue
Package Namehypervel/config
TypeLibrary
NamespaceHypervel\Config
PHP Version^8.2
LicenseMIT
Primary Dependencieshyperf/config (~3.1.0), hyperf/macroable (~3.1.0)

Sources: composer.json1-47


Role in the Framework Ecosystem

Package Position in Framework Architecture


The package serves as the configuration layer between Hyperf's core framework and application code. It implements Hyperf\Contract\ConfigInterface while extending functionality through automatic discovery and enhanced merging capabilities.

Sources: composer.json31-35 composer.json40-42

Core Capabilities

The package provides the following capabilities:

CapabilityImplementationDescription
Automatic DiscoveryProviderConfig::load()Discovers configurations from composer.json extra fields (hyperf.config, hypervel.config, hypervel.providers) across all installed packages
Configuration MergingProviderConfig::mergeTwo()Sophisticated recursive merging algorithm with special handling for numeric keys (deduplication), string keys (recursive merge), and PriorityDefinition objects
File-Based LoadingConfigFactory::readConfig(), ConfigFactory::readPaths()Loads configurations from config/hyperf.php and scans config/autoload/*.php files
Type-Safe AccessRepository::string(), Repository::integer(), etc.Type-safe getter methods that validate and cast configuration values
Global Helperconfig() function in src/Functions.phpGlobal function for convenient configuration access throughout the application
Array OperationsRepository::push(), Repository::prepend()Array manipulation methods for modifying array configuration values
Configuration CallbacksRepository::afterSettingCallback()Register callbacks that execute after configuration values are changed

Sources: composer.json27-29


System Architecture

The configuration system consists of five primary components that work together in a sequential pipeline:

Component Pipeline Architecture


Each component has a distinct responsibility in the configuration lifecycle:

ComponentFile PathTypeResponsibility
ProviderConfigsrc/ProviderConfig.phpStatic ClassDiscovers and merges configurations from composer packages, service providers, and invokable classes
ConfigFactorysrc/ConfigFactory.phpInvokable FactoryAggregates provider configs with file-based configs; creates Repository instances
Repositorysrc/Repository.phpClassStores configuration data; provides typed access methods and array operations
Repository Contractsrc/Contract/Repository.phpInterfaceDefines the configuration storage contract; extends ConfigInterface
ConfigProvidersrc/ConfigProvider.phpClassRegisters configuration system with Hyperf's DI container
config()src/Functions.phpGlobal FunctionProvides global access to configuration via dependency injection

Sources: composer.json24-29


Configuration Data Flow

Configuration Loading and Access Pipeline


The system processes configuration data through four distinct phases:

  1. Discovery Phase: ProviderConfig::load() discovers configurations from composer packages and service providers via ProviderConfig::loadProviders()
  2. Aggregation Phase: ConfigFactory::__invoke() combines provider configs with file-based configs using ProviderConfig::mergeTwo() algorithm
  3. Instantiation Phase: Creates a Repository instance populated with the final merged configuration array
  4. Access Phase: config() function retrieves the Repository from Hyperf's DI container

Sources: composer.json27-29


Key Design Patterns

The package employs several architectural patterns to achieve flexibility and maintainability:

PatternImplementationPurpose
Discovery PatternProviderConfig classAutomatically discovers configuration sources without manual registration
Factory PatternConfigFactory invokable classCentralizes Repository creation logic; registered in DI as factory
Repository PatternRepository class implementing Repository interfaceAbstracts configuration storage from access mechanisms
Facade Patternconfig() global functionProvides simple, static-like access to configuration
Dependency InjectionConfigProvider registrationIntegrates with Hyperf's container for loose coupling

Sources: composer.json24-29 composer.json40-42


File System Structure

Package File Organization


The package follows PSR-4 autoloading with the namespace Hypervel\Config mapped to the src/ directory at composer.json24-26 The Functions.php file is autoloaded via Composer's files directive at composer.json27-29 to register the global config() function.

Sources: composer.json23-29


Integration with Hyperf

Hyperf Integration Mechanism


The integration occurs through:

  1. Hyperf discovers Hypervel\Config\ConfigProvider via composer.json extra.hyperf.config field at composer.json39-42
  2. ConfigProvider::__invoke() registers dependencies with the DI container
  3. Hyperf\Contract\ConfigInterface resolves to ConfigFactory, which creates Repository instances
  4. Application code accesses configuration through injected ConfigInterface or the config() function defined in src/Functions.php27-29

Sources: composer.json39-42 composer.json27-29


Component Interaction Summary

The components interact through a well-defined sequence:

StepComponentActionOutput
1ProviderConfigDiscovers and merges provider configurationsCached provider config array
2ConfigFactoryAggregates provider + file configsFinal merged array
3RepositoryStores configuration dataAccessible configuration object
4ConfigProviderRegisters with DI containerContainer binding
5config()Resolves Repository from containerConfiguration access

For detailed information about the discovery and merging process, see Provider Config Discovery and Merging.
For the aggregation process, see Config Factory and Aggregation.
For usage of the Repository, see Repository Class.
For the global helper function, see Configuration Function.

Sources: composer.json1-47 README.md1-3