VOOZH about

URL: https://deepwiki.com/hypervel/dispatcher/3-configuration

⇱ Configuration | hypervel/dispatcher | DeepWiki


Loading...
Menu

Configuration

This document details how the hypervel/dispatcher package registers itself with the Hyperf framework through its ConfigProvider class. It explains the class mapping mechanism that allows the package to override Hyperf's default HttpRequestHandler and describes the automatic discovery and loading process during application bootstrap.

For information about the actual HTTP request handling implementation, see HTTP Request Handler. For details on how to integrate this package into an application, see Integration Guide.

Configuration Provider Overview

The ConfigProvider class serves as the integration point between the hypervel/dispatcher package and the Hyperf framework's dependency injection container. Hyperf automatically discovers and invokes this configuration provider during application bootstrap.

The configuration provider is registered in composer.json34-37 through the extra.hyperf.config key:


The ConfigProvider class itself is implemented in src/ConfigProvider.php9-23 and returns a configuration array that instructs Hyperf to override specific framework classes.

Sources: composer.json1-47 src/ConfigProvider.php1-24

Configuration Discovery Flow

The following diagram illustrates how Hyperf discovers and loads the configuration from the hypervel/dispatcher package during application bootstrap:


Sources: composer.json34-37 src/ConfigProvider.php9-23

Class Mapping Mechanism

The core purpose of the configuration is to replace Hyperf's default HttpRequestHandler with Hypervel's custom implementation. This is achieved through the class_map configuration mechanism.

Configuration Structure

The ConfigProvider::__invoke() method in src/ConfigProvider.php11-22 returns the following structure:

Configuration KeyPurpose
annotations.scan.class_mapMaps fully-qualified class names to replacement file paths
HttpRequestHandler::classMaps Hyperf\Dispatcher\HttpRequestHandler to the custom implementation file
__DIR__ . '/../class_map/HttpRequestHandler.php'Points to the replacement implementation file path

The configuration array structure:


Class Mapping Resolution

The following diagram shows how the class mapping resolves requests for HttpRequestHandler:


Sources: src/ConfigProvider.php11-22

Bootstrap Integration Process

The integration occurs automatically through Hyperf's configuration discovery mechanism. The following table outlines the bootstrap phases:

PhaseComponentActionResult
1. Package DiscoveryComposerReads composer.json extra configurationIdentifies ConfigProvider class
2. Provider RegistrationHyperf ContainerCollects all package config providersBuilds provider registry
3. Configuration LoadingHyperf ContainerInvokes each ConfigProvider::__invoke()Collects configuration arrays
4. Configuration MergingHyperf ContainerMerges all configurationsUnified application configuration
5. Class Map ProcessingAnnotation ScannerProcesses class_map entriesRegisters class overrides
6. Container BindingHyperf ContainerBinds classes to implementationsHttpRequestHandler resolves to Hypervel version

Implementation Details

The ConfigProvider implementation in src/ConfigProvider.php9-23 follows this structure:

  • Namespace: Hypervel\Dispatcher
  • Method: __invoke(): array - Returns configuration array when invoked by Hyperf
  • Import: Uses Hyperf\Dispatcher\HttpRequestHandler to reference the class being overridden
  • Path Resolution: Uses __DIR__ . '/../class_map/HttpRequestHandler.php' for relative path to replacement file

The configuration provider does not require any constructor dependencies or service injection. It is a pure configuration object that returns static configuration data.

Sources: src/ConfigProvider.php1-24

Configuration Registration Diagram

This diagram maps the concrete code entities involved in the configuration process:


Sources: composer.json34-37 src/ConfigProvider.php1-24

Configuration Behavior

Automatic Discovery

The package requires no manual configuration or registration steps. Once installed via Composer, Hyperf automatically:

  1. Detects the package through extra.hyperf.config in composer.json35-36
  2. Instantiates Hypervel\Dispatcher\ConfigProvider from src/ConfigProvider.php9
  3. Invokes the __invoke() method from src/ConfigProvider.php11
  4. Processes the returned configuration array

Class Override Behavior

When the class mapping is active:

  • Any request for Hyperf\Dispatcher\HttpRequestHandler resolves to the file at class_map/HttpRequestHandler.php
  • The original Hyperf implementation is never loaded
  • All type hints and dependency injections for HttpRequestHandler receive the Hypervel version
  • The override is transparent to application code

No Runtime Configuration

The ConfigProvider does not expose any runtime configuration options. The class mapping is static and determined at bootstrap time. Applications cannot modify or disable this behavior without removing the package.

Sources: src/ConfigProvider.php1-24 composer.json34-37