VOOZH about

URL: https://deepwiki.com/hypervel/object-pool/5-integration-and-configuration

⇱ Integration & Configuration | hypervel/object-pool | DeepWiki


Loading...
Menu

Integration & Configuration

This section provides an overview of how the hypervel/object-pool package integrates with the Hyperf framework ecosystem. The package is designed as a Hyperf component that leverages the framework's dependency injection container, event system, and coroutine engine.

Subsection Overview

This integration overview is organized into the following subsections:

  • Configuration Provider: Details on the ConfigProvider class that registers services and listeners in the Hyperf container
  • Framework Integration: Explanation of how the package integrates with Hyperf's coroutines, events, and dependency injection system
  • Contracts & Interfaces: Reference documentation for all interfaces and contracts used throughout the system

For pool-specific configuration options, see Pool Configuration.

Technology Stack & Dependencies

The package requires PHP 8.2+ and is built on top of Hyperf 3.1 framework components. The following table shows the core dependencies defined in composer.json:

PackageVersionPurpose
php^8.2Minimum PHP version requirement
hyperf/coroutine~3.1.0Coroutine context detection and management
hyperf/engine^2.1Swoole/Swow abstraction layer for coroutine channels
hyperf/coordinator~3.1.0Task coordination and lifecycle management
hyperf/contract~3.1.0PSR-11 container interfaces
hyperf/support~3.1.0Helper utilities
nesbot/carbon^2.72.6Date/time manipulation for recycling timestamps

Package Registration

The package is registered in Hyperf's auto-discovery system through the extra.hyperf.config section:


This configuration tells Hyperf to automatically load the ConfigProvider class during application bootstrap.

Sources: composer.json23-30 composer.json37-40

Integration Architecture

The object pooling system integrates with Hyperf through PSR-11 dependency injection and event-driven lifecycle management. The integration follows a layered architecture where ConfigProvider handles service registration, StartRecycler manages lifecycle automation, and contracts define clear boundaries between components.

Dependency Injection Configuration Flow

Diagram: Service Registration and Initialization Flow


Sources: src/ConfigProvider.php1-26 src/Listeners/StartRecycler.php1-32

Service Registration Mapping

The ConfigProvider class defines the core service mappings that wire the pooling system into the dependency injection container:

InterfaceImplementationPurpose
Hypervel\ObjectPool\Contracts\FactoryHypervel\ObjectPool\PoolManagerProvides pool creation and management services
Hypervel\ObjectPool\Contracts\RecyclerHypervel\ObjectPool\ObjectRecyclerHandles automated object lifecycle management

Sources: src/ConfigProvider.php16-18

Event-Driven Initialization

Diagram: Application Lifecycle and Recycler Startup


Sources: src/ConfigProvider.php14-24 src/Listeners/StartRecycler.php19-30

Configuration Provider Implementation

The ConfigProvider class at src/ConfigProvider.php1-26 serves as the central integration point between the object pooling system and Hyperf's dependency injection container. It implements the standard Hyperf configuration provider pattern by exposing an __invoke() method that returns configuration arrays.

Core Configuration Structure

The configuration provider returns a structured array with two primary sections:

Section KeyPurposeType
dependenciesMaps interface contracts to concrete implementationsarray<class-string, class-string>
listenersRegisters event listeners for lifecycle automationarray<class-string>

Dependencies Section: Enables automatic dependency resolution through constructor injection. When application code requests Factory::class or Recycler::class, the container automatically resolves them to their concrete implementations.

Listeners Section: Registers the StartRecycler class as an event listener, which responds to the AfterWorkerStart event to initialize the recycling subsystem.

Sources: src/ConfigProvider.php14-24

Contract-to-Implementation Mapping

Diagram: Dependency Resolution Chain


Sources: src/ConfigProvider.php7-9 src/ConfigProvider.php16-18 src/ConfigProvider.php20-22

Framework Compatibility

The integration architecture is designed to work with PSR-11 compatible dependency injection containers. While optimized for Hyperf, the system can be adapted to other frameworks that support:

  • PSR-11 container interfaces
  • Event listener registration
  • Service provider patterns
  • Automatic service resolution

Required Framework Features

FeaturePurposeHyperf Implementation
PSR-11 ContainerService resolution and dependency injectionHyperf\Di\Container
Event SystemAutomated lifecycle managementHyperf\Event\EventDispatcher
Configuration ProvidersService registrationHyperf\ConfigProvider pattern
Worker Process EventsRecycling system initializationHyperf\Framework\Event\AfterWorkerStart

The ConfigProvider class acts as an adapter between the object pooling system and the framework's configuration system, ensuring clean separation of concerns and framework-agnostic design where possible.

Sources: src/ConfigProvider.php1-26