VOOZH about

URL: https://deepwiki.com/hypervel/components/9.2-manager-pattern-for-driver-resolution

⇱ Manager Pattern for Driver Resolution | hypervel/components | DeepWiki


Loading...
Last indexed: 7 March 2026 (96fbab)
Menu

Manager Pattern for Driver Resolution

Purpose: This document describes the Manager abstract class and its role in implementing a driver resolution pattern used throughout Hypervel. The Manager pattern provides a unified approach for creating, caching, and accessing different driver implementations of services such as cache stores, broadcasting channels, and queue connections.

For information about the DataObject pattern, see DataObject Pattern. For service provider lifecycle and registration, see Service Providers and Bootstrapping.


Overview

The Manager pattern is a factory-based design pattern that enables Hypervel to support multiple driver implementations for the same service interface. It provides:

  • Lazy instantiation: Drivers are created only when first accessed
  • Instance caching: Once created, driver instances are reused
  • Custom driver registration: Developers can register custom implementations via closures
  • Convention-based creation: Standard naming conventions for driver creator methods
  • Method proxying: Automatic delegation to the default driver

This pattern is used by CacheManager, BroadcastManager, QueueManager, and other manager classes throughout the framework.

Sources: src/support/src/Manager.php1-158


Core Manager Architecture

Manager Abstract Class Structure

The Manager class provides the foundation for all driver-based managers in Hypervel.


Sources: src/support/src/Manager.php13-157


Driver Resolution Flow

The driver resolution process follows a specific sequence to locate and instantiate the appropriate driver implementation.

Resolution Sequence Diagram


Sources: src/support/src/Manager.php49-84


Driver Creation Strategies

The Manager pattern supports two complementary strategies for driver creation: convention-based methods and custom closures.

Convention-Based Driver Creation

Manager subclasses define driver creator methods following the naming pattern create{DriverName}Driver().

Driver NameMethod NameNaming Convention
rediscreateRedisDriver()create + StudlyCase(driver) + Driver
filecreateFileDriver()Uses Str::studly() for transformation
pusher-beamscreatePusherBeamsDriver()Handles hyphens and underscores

The method name is constructed using the following logic:


Implementation:

src/support/src/Manager.php68-84 - The createDriver() method attempts to call the convention-based method if it exists:


Sources: src/support/src/Manager.php68-84 src/support/src/Manager.php9


Custom Driver Registration

The extend() method allows runtime registration of custom driver implementations via closures.

Method Signature:

src/support/src/Manager.php99-104


Usage Pattern:


Custom Creator Invocation:

src/support/src/Manager.php89-92 - Custom creators receive the container instance as their argument:


Sources: src/support/src/Manager.php99-104 src/support/src/Manager.php89-92


Driver Caching and Instance Management

Driver Instance Cache

The Manager maintains a simple associative array to cache driver instances by name.

Cache Structure:

src/support/src/Manager.php28


Cache Storage Logic:

src/support/src/Manager.php49-61


Cache Management Methods

MethodPurposeSource
getDrivers()Retrieve all cached driver instancessrc/support/src/Manager.php109-112
forgetDrivers()Clear all cached instancessrc/support/src/Manager.php139-144

Cache Lifetime:


Sources: src/support/src/Manager.php28 src/support/src/Manager.php49-61 src/support/src/Manager.php109-112 src/support/src/Manager.php139-144


Method Proxying with __call

The __call magic method enables transparent proxying of method calls to the default driver instance.

Proxy Mechanism


Implementation:

src/support/src/Manager.php153-156


Usage Examples:


Sources: src/support/src/Manager.php153-156


Container and Configuration Integration

Dependency Injection

The Manager pattern integrates tightly with Hypervel's dependency injection container.

Constructor Dependencies:

src/support/src/Manager.php33-37


Container Access Methods:

MethodPurposeSource
getContainer()Retrieve the container instancesrc/support/src/Manager.php117-120
setContainer()Replace the container instancesrc/support/src/Manager.php127-132

Configuration Resolution

Manager subclasses typically read configuration to determine the default driver and driver-specific settings.


Abstract Method Requirement:

src/support/src/Manager.php42


Typical Implementation Pattern:


Sources: src/support/src/Manager.php33-37 src/support/src/Manager.php42 src/support/src/Manager.php117-132


Manager Pattern Throughout Hypervel

The Manager pattern is used extensively across Hypervel's service layer to provide consistent driver-based architecture.

Framework Manager Implementations

Manager ClassConfiguration KeyPurposeDriver Examples
CacheManagercache.defaultCache store selectionredis, file, array, swoole, stack, database
BroadcastManagerbroadcasting.defaultEvent broadcaster selectionpusher, ably, redis, log, null
QueueManagerqueue.defaultQueue connection selectionredis, database, sync, null
SessionManagersession.driverSession storage selectionfile, cookie, database, redis, array

Driver Resolution Example: CacheManager


Sources: Referenced from high-level architecture diagrams, src/support/src/Manager.php1-158


Advanced Usage Patterns

Multi-Connection Driver Usage

The Manager pattern allows accessing multiple driver instances simultaneously:


Runtime Driver Switching


Custom Driver with Dependencies


Testing with Driver Substitution


Sources: src/support/src/Manager.php49-104


Key Design Benefits

The Manager pattern provides several architectural advantages:

  1. Separation of Concerns: Driver selection logic is separated from driver implementation
  2. Lazy Loading: Drivers are only instantiated when needed, reducing memory overhead
  3. Configuration-Driven: Default drivers are determined by configuration, enabling environment-specific behavior
  4. Extensibility: Custom drivers can be registered without modifying core classes
  5. Testability: Driver instances can be easily swapped for testing purposes
  6. Type Safety: Subclasses can provide specific return types for their driver methods

Sources: src/support/src/Manager.php1-158