VOOZH about

URL: https://deepwiki.com/hypervel/dispatcher

⇱ hypervel/dispatcher | DeepWiki


Loading...
Menu

Overview

The hypervel/dispatcher package provides HTTP request handling and middleware pipeline execution for the Hypervel framework. Built on Hyperf 3.1.0, the package extends Hyperf's core dispatcher and pipeline components to support multiple middleware formats including PSR-15 standard middleware, closures, and string-based middleware definitions.

The package overrides Hyperf's default HttpRequestHandler implementation through class mapping, providing enhanced middleware processing capabilities while maintaining compatibility with the Hyperf ecosystem and Swoole asynchronous runtime.

For detailed information about specific components, see:

  • Page 1.1: Package Structure and Dependencies
  • Page 2.1: HttpRequestHandler Implementation
  • Page 2.2: Pipeline Implementation
  • Page 2.3: Middleware Adaptation System
  • Page 3: Configuration and Integration

Purpose and Scope

The hypervel/dispatcher package serves as the HTTP request dispatcher for Hypervel applications. Core responsibilities include:

ResponsibilityImplementation
Request handlingHttpRequestHandler implements PSR-15 RequestHandlerInterface
Middleware executionPipeline extends Hyperf\Pipeline\Pipeline
Middleware adaptationPsr15AdapterMiddleware and AdaptedRequestHandler bridge different middleware standards
String parsingParsedMiddleware parses middleware signatures like 'auth:api,admin'
Framework integrationConfigProvider registers class mappings with Hyperf DI container

Sources: composer.json1-46

Core Components

The package consists of five primary classes in the Hypervel\Dispatcher namespace:

Component Relationships


Component Reference Table

ClassLocationPurpose
HttpRequestHandlerclass_map/HttpRequestHandler.phpPSR-15 request handler, orchestrates middleware pipeline execution
Pipelinesrc/Pipeline.phpExtends Hyperf's pipeline to resolve and adapt middleware
Psr15AdapterMiddlewaresrc/Middleware/Psr15AdapterMiddleware.phpAdapts PSR-15 middleware to closure-based execution
AdaptedRequestHandlersrc/Middleware/AdaptedRequestHandler.phpWraps closures as PSR-15 RequestHandlerInterface
ParsedMiddlewaresrc/ParsedMiddleware.phpParses string middleware signatures into name and parameters
ConfigProvidersrc/ConfigProvider.phpRegisters package with Hyperf DI container

Sources: composer.json29-33 composer.json35-37

Request Processing Flow

The HttpRequestHandler receives PSR-7 ServerRequestInterface objects and processes them through a middleware pipeline before returning PSR-7 ResponseInterface objects.

Request Lifecycle Sequence


Middleware execution operates on a pass-through model where each middleware receives:

  • ServerRequestInterface $request - The current request object
  • Closure $next - Handler to invoke the next middleware

Middleware can:

  • Transform the request before passing to $next()
  • Return a response directly to short-circuit the pipeline
  • Transform the response returned from $next()

The Pipeline stores middleware configuration in Hyperf\Context\Context under the key http.request.middleware for access by downstream components.

Sources: composer.json25-27

Middleware Type Support

The Pipeline class resolves and adapts four middleware formats into a uniform execution model:

Middleware Resolution Flow


Middleware Type Reference

TypeFormatResolutionExample
ClosureClosureDirect executionfunction($request, $next) { return $next($request); }
PSR-15Class implementing MiddlewareInterfaceWrapped in Psr15AdapterMiddlewareAuthMiddleware::class
String'name:param1,param2'Parsed by ParsedMiddleware, resolved via DI container'auth:api,admin'
CoreMiddlewareClass implementing CoreMiddlewareInterfaceWrapped in Psr15AdapterMiddlewareCoreMiddleware::class

The Psr15AdapterMiddleware converts PSR-15's two-parameter signature process(ServerRequestInterface, RequestHandlerInterface) to Hypervel's closure-based signature by wrapping the $next closure in an AdaptedRequestHandler instance.

See Page 2.3 for detailed implementation of the adaptation system.

Sources: composer.json25-27

Hyperf Framework Integration

The package extends and integrates with three core Hyperf 3.1.0 components:

Dependency Architecture


Framework Dependencies

DependencyVersionPurpose
hyperf/context~3.1.0Request-scoped context storage via Context::set() and Context::get()
hyperf/dispatcher~3.1.0Base dispatcher classes that HttpRequestHandler extends
hyperf/pipeline~3.1.0Pipeline pattern implementation that Pipeline extends

The ConfigProvider registers a class mapping that overrides the default Hyperf HttpRequestHandler with the Hypervel implementation. This mapping is defined in class_map/HttpRequestHandler.php and registered through the extra.hyperf.config entry in composer.json.

See Page 3 for detailed configuration information.

Sources: composer.json23-28 composer.json35-37

System Requirements and Installation

Hypervel Dispatcher requires:

  • PHP 8.2 or higher
  • Hyperf framework components (specifically hyperf/context, hyperf/dispatcher, hyperf/pipeline)

The package can be installed via Composer:


After installation, the dispatcher is automatically registered with Hyperf's dependency injection container via the ConfigProvider class.

Sources: composer.json23-27 composer.json35-37

License

Hypervel Dispatcher is licensed under the MIT License.

Sources: composer.json4