VOOZH about

URL: https://deepwiki.com/hypervel/event/6.3-package-structure-and-dependencies

⇱ Package Structure and Dependencies | hypervel/event | DeepWiki


Loading...
Menu

Package Structure and Dependencies

This document describes the physical organization of the hypervel/event package, including its dual namespace architecture, dependency requirements, PSR standards compliance, and integration points with external frameworks. This provides the foundation for understanding how the package fits into both Hyperf and Laravel ecosystems.

For information about how the factories wire up these dependencies at runtime, see Factory System and Dependency Injection. For details on the specific interfaces and contracts, see Contracts and Interfaces.


Dual Namespace Architecture

The package implements a dual namespace strategy to provide compatibility with both Hyperf and Laravel codebases. This allows code written for Laravel's event system to work with minimal modifications while providing native Hyperf integration.

Namespace Mapping


Dual Namespace Mapping

Sources: composer.json24-27

The autoloading configuration defines two PSR-4 namespace roots:

NamespaceDirectoryPurpose
Hypervel\Event\src/Native implementation with Hyperf integration
Illuminate\Events\illuminate/Laravel-compatible queue job wrappers
Functionssrc/Functions.phpGlobal helper functions (event(), queueable())

Rationale for Dual Namespaces

The Illuminate\Events\ namespace provides compatibility classes that match Laravel's queue system expectations:

This approach allows the package to work seamlessly in both ecosystems without requiring changes to existing Laravel-based event listeners.

Sources: composer.json24-30 src/EventDispatcher.php25


Directory Structure


Package Directory Organization

Sources: composer.json24-30


Core Dependencies

The package requires several Hyperf framework components and integrates with Laravel's closure serialization library.

Required Dependencies Table

PackageVersionPurposeUsed By
php^8.2Modern PHP features (enums, readonly, union types)All classes
hyperf/event~3.1.0Base event interfaces, ListenerProvider parent classListenerProvider
hyperf/collection~3.1.0Array manipulation utilities (Arr class)EventDispatcher, ListenerProvider
hyperf/context~3.1.0Coroutine-safe context storageEventDispatcher, deferred events
hyperf/stringable~3.1.0String parsing utilities (Str::parseCallback)EventDispatcher
hypervel/bus~0.1Command bus integrationTransaction-aware dispatching
laravel/serializable-closure^1.3Serialize closures for queue storageQueuedClosure, queue integration

Sources: composer.json32-39

Dependency Usage in Code


Direct Dependency Usage Mapping

Sources: src/EventDispatcher.php9-12 composer.json32-39

Key Dependency Purposes

Hyperf Collection (hyperf/collection)

Used extensively for array operations. Key usage at src/EventDispatcher.php535 with Arr::wrap() for normalizing listener arrays during subscriber registration.

Hyperf Context (hyperf/context)

Enables coroutine-safe storage for deferred events. Critical for the defer() method implementation at src/EventDispatcher.php573-598 Context keys used:

  • __event.deferring - Whether currently in defer mode
  • __event.deferred_events - Buffered events waiting for dispatch
  • __event.events_to_defer - Whitelist of events to defer

Hyperf Stringable (hyperf/stringable)

Provides the Str::parseCallback() utility at src/EventDispatcher.php299 to parse class-based listener strings (e.g., "MyListener@handle"["MyListener", "handle"]).

Laravel SerializableClosure (laravel/serializable-closure)

Required for QueuedClosure to wrap PHP closures for queue storage. Closures are not naturally serializable, so this package uses reflection to extract closure code and context.

Sources: src/EventDispatcher.php9-12 src/EventDispatcher.php299 src/EventDispatcher.php535 src/EventDispatcher.php573-598


Optional Dependencies

Queue Integration

The package suggests but does not require hypervel/queue for asynchronous event processing:


Sources: composer.json41-43

When hypervel/queue is not available:

  • Events with ShouldQueue listeners will still be registered but cannot be queued
  • QueuedClosure can be instantiated but fails at dispatch time
  • The queue resolver must be set via EventDispatcher::setQueueResolver() src/EventDispatcher.php369-374

Queue Dependency Usage


Queue Dependency Resolution

Sources: src/EventDispatcher.php20-23 src/EventDispatcher.php359-362 src/EventDispatcher.php397-408

The queue factory is resolved lazily through a callback set by EventDispatcherFactory:


PSR Standards Compliance

The package extends and implements multiple PSR (PHP Standards Recommendations) interfaces to ensure interoperability.

PSR Interface Implementations


PSR Standards Integration

Sources: src/EventDispatcher.php27-28 src/EventDispatcher.php31

PSR-14: Event Dispatcher Standard

The core interfaces extend PSR-14 to ensure compatibility with any PSR-14 compliant system:

  • EventDispatcherInterface: Defines dispatch(object $event) contract
  • ListenerProviderInterface: Defines getListenersForEvent(object $event): iterable
  • StoppableEventInterface: Checked at src/EventDispatcher.php168 to halt propagation

PSR-11: Container Interface

Used for dependency resolution at multiple points:

The container is optional and falls back to ApplicationContext::getContainer() if not provided.

PSR-3: Logger Interface

Optional logging support at src/EventDispatcher.php93-111:


When a LoggerInterface implementation is provided, the dispatcher logs each listener execution.

Sources: src/EventDispatcher.php27-28 src/EventDispatcher.php49-57 src/EventDispatcher.php93-111 src/EventDispatcher.php168


Autoloading Configuration

The composer autoload configuration enables both PSR-4 class loading and function file inclusion.

Autoload Directives


Autoload Configuration Flow

Sources: composer.json23-31

Function File Loading

The package includes a functions file with global helpers:


This file is loaded on every request, providing the event() and queueable() helper functions that facade the event dispatcher. These functions are documented in Helper Functions.

Sources: composer.json28-30


Framework Integration Points

The package integrates with multiple frameworks through specific extension points and configuration mechanisms.

Hyperf Framework Integration


Hyperf Integration Architecture

Sources: composer.json48-50

The ConfigProvider class is automatically discovered through Hyperf's package scanning:


This hooks into Hyperf's dependency injection system to register factories and discover listener annotations. The full factory system is covered in Factory System and Dependency Injection.

Laravel Ecosystem Compatibility

While built on Hyperf, the package maintains Laravel API compatibility through:

  1. Illuminate namespace classes in illuminate/ directory
  2. Laravel-style method signatures (e.g., listen(), dispatch(), until())
  3. Laravel queue job format via CallQueuedListener matching Laravel's expectations
  4. SerializableClosure integration for closure serialization

This dual compatibility allows:

  • Migration of Laravel event listeners to Hyperf
  • Use of Laravel queue workers with Hyperf-generated jobs
  • Familiarity for developers transitioning from Laravel

Sources: composer.json24-27 composer.json39


External Dependency Integration

Transaction Manager Integration

The package integrates with Hypervel\Database\TransactionManager (from hypervel/bus) for transaction-aware event dispatching:

The transaction manager is optional; if not available, transaction-aware features gracefully degrade to immediate dispatch.

Broadcasting Integration

Integration with Hypervel\Broadcasting\Contracts\Factory enables real-time event broadcasting:

Events implementing ShouldBroadcast are automatically queued to broadcasting channels. See Event Broadcasting for details.

Sources: src/EventDispatcher.php13-15 src/EventDispatcher.php78-85 src/EventDispatcher.php197-200 src/EventDispatcher.php379-382


Dependency Resolution Patterns

The package uses lazy resolver callbacks for optional dependencies to avoid hard coupling:


Lazy Dependency Resolution Pattern

Sources: src/EventDispatcher.php36-47 src/EventDispatcher.php359-392

Queue Resolver Pattern

The queue factory is resolved through a callback:

This allows the queue to be unavailable at construction time and resolved only when needed for queued listeners.

Transaction Manager Resolver Pattern

Similarly, the transaction manager uses lazy resolution:

Returns null if no transaction manager is available, allowing graceful degradation.

Sources: src/EventDispatcher.php36-47 src/EventDispatcher.php359-392


Version Constraints and Compatibility

Hyperf Version Targeting

All Hyperf dependencies target version ~3.1.0, ensuring compatibility with Hyperf 3.1.x releases:


This constraint allows patch and minor version updates within 3.1.x while preventing breaking changes from 3.2.x.

PHP Version Requirement

Requires PHP ^8.2 to leverage modern language features:

  • Union types (e.g., object|string)
  • Readonly properties
  • Constructor property promotion
  • Enums (used in contracts)

Package Versioning

The package uses semantic versioning with branch alias:


The 0.3-dev alias indicates pre-1.0 development status. Breaking changes may occur between minor versions (0.x releases).

Sources: composer.json32-39 composer.json51-53


Summary

The hypervel/event package employs a sophisticated structure that bridges multiple ecosystems:

AspectImplementation
Namespace StrategyDual: Hypervel\Event\ (native) + Illuminate\Events\ (compatibility)
Core FrameworkHyperf 3.1.x with PSR-14 compliance
Optional FeaturesQueue via hypervel/queue, transactions via hypervel/bus
Laravel IntegrationThrough laravel/serializable-closure and compatible job format
PHP Version8.2+ for modern language features
Dependency ResolutionLazy resolver pattern for optional services

This architecture enables the package to serve as a high-performance event system for Hyperf applications while maintaining API familiarity for Laravel developers and providing optional integrations with queue and transaction systems.

Sources: composer.json1-55 src/EventDispatcher.php1-618

Refresh this wiki

On this page