VOOZH about

URL: https://deepwiki.com/hypervel/bus/2-installation-and-configuration

⇱ Installation and Configuration | hypervel/bus | DeepWiki


Loading...
Menu

Installation and Configuration

This page documents the installation process for the hypervel/bus package and explains how it integrates with a Hyperf application. The page covers Composer installation, automatic service registration through the ConfigProvider, and the dependency injection setup that makes the bus system available throughout your application.

For information about how to use the dispatch functions after installation, see Dispatch Functions. For details on the internal architecture and design patterns, see Architecture and System Design.


Requirements

The hypervel/bus package requires the following dependencies:

DependencyVersion ConstraintPurpose
PHP^8.2Minimum PHP version
hyperf/context~3.1.0Coroutine context management
hyperf/contract~3.1.0Framework contracts
hyperf/collection~3.1.0Data collections
hyperf/conditionable~3.1.0Conditional logic support
hyperf/coroutine~3.1.0Coroutine utilities
hyperf/support~3.1.0Framework utilities
nesbot/carbon^2.72.6Date/time handling
laravel/serializable-closure^1.3Closure serialization
hypervel/support^0.3Hypervel utilities
hypervel/cache^0.3Caching layer for batch data

The package also suggests installing hypervel/queue for advanced job chaining with closures.

Sources: composer.json23-35 composer.json53-55


Installation

Install the package via Composer:


Once installed, the package automatically registers itself with your Hyperf application through the Hyperf auto-discovery mechanism.

Sources: composer.json2


Package Auto-Discovery

The hypervel/bus package uses Hyperf's package discovery system to automatically configure itself. This is defined in the composer.json file's extra.hyperf section:


When your Hyperf application boots, it automatically discovers and loads the Hypervel\Bus\ConfigProvider class, which registers all necessary services into the dependency injection container.

Sources: composer.json45-51


Service Registration Architecture

The following diagram shows how services are registered during application bootstrap:


Sources: composer.json45-51 src/ConfigProvider.php11-22


ConfigProvider Details

The ConfigProvider class is responsible for registering all bus-related services. It implements a simple __invoke() method that returns a configuration array:


This configuration establishes three key service bindings:

  1. Dispatcher Service: Maps Hypervel\Bus\Contracts\Dispatcher to Hypervel\Bus\DispatcherFactory
  2. Batch Repository Interface: Maps Hypervel\Bus\Contracts\BatchRepository to Hypervel\Bus\DatabaseBatchRepository via a closure
  3. Database Repository Concrete: Maps Hypervel\Bus\DatabaseBatchRepository to Hypervel\Bus\DatabaseBatchRepositoryFactory

Sources: src/ConfigProvider.php13-21


Dependency Injection Bindings

The following table details each service binding registered by the ConfigProvider:

Interface/ClassFactory/ImplementationResolution Type
Hypervel\Bus\Contracts\DispatcherHypervel\Bus\DispatcherFactoryFactory class
Hypervel\Bus\Contracts\BatchRepositoryHypervel\Bus\DatabaseBatchRepositoryClosure that resolves from container
Hypervel\Bus\DatabaseBatchRepositoryHypervel\Bus\DatabaseBatchRepositoryFactoryFactory class

Factory Pattern Usage

The package uses the Factory pattern for complex service construction. Instead of directly instantiating services, the container delegates to factory classes:

  • DispatcherFactory: Constructs the Dispatcher instance with necessary dependencies
  • DatabaseBatchRepositoryFactory: Constructs the DatabaseBatchRepository with configuration and dependencies

This pattern enables:

  • Lazy instantiation of services
  • Complex dependency resolution
  • Easy testing with mock implementations

Sources: src/ConfigProvider.php16-19


Service Resolution Flow

The following diagram illustrates how services are resolved at runtime when user code requests the dispatcher:


Sources: src/ConfigProvider.php16-19


Autoloading Configuration

The package configures PSR-4 autoloading for its namespace and also autoloads the helper functions file:


This configuration ensures that:

  • All classes under the Hypervel\Bus namespace are autoloaded from the src/ directory
  • The global dispatch() and dispatch_sync() helper functions are automatically available (see Dispatch Functions)

Sources: composer.json37-43


Post-Installation Verification

After installation, verify that the package is correctly configured:

1. Check Service Registration

Verify that the dispatcher can be resolved from the container:


2. Verify Helper Functions

Ensure the global helper functions are available:


3. Check Batch Repository

Verify the batch repository is accessible:


Sources: composer.json41-43 src/ConfigProvider.php16-19


No Additional Configuration Required

Unlike some packages, hypervel/bus requires no additional configuration files or environment variables for basic operation. The package works out-of-the-box with sensible defaults:

  • The dispatcher is ready to dispatch jobs synchronously or to queues
  • Batch processing uses the default database connection
  • All services are automatically wired through dependency injection

For advanced batch storage configuration, see Database Implementation. For queue-specific configuration, see Queue Integration.

Sources: src/ConfigProvider.php11-22


Integration with Hyperf Ecosystem

The following diagram shows how hypervel/bus integrates with other Hyperf and Hypervel packages:


Sources: composer.json23-35 composer.json53-55


Summary

After running composer require hypervel/bus, the package:

  1. Installs Dependencies: All required Hyperf and Hypervel packages are automatically installed
  2. Registers Services: The ConfigProvider is discovered and registers three key services into the DI container
  3. Autoloads Functions: The dispatch() and dispatch_sync() global functions become available
  4. Configures Namespace: PSR-4 autoloading is configured for the Hypervel\Bus namespace

No additional configuration steps are required. The package is ready to use immediately. To begin dispatching jobs, see Dispatching Jobs.

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