VOOZH about

URL: https://deepwiki.com/hypervel/telescope/3.2-hyperf-and-hypervel-integration

⇱ Hyperf and Hypervel Integration | hypervel/telescope | DeepWiki


Loading...
Last indexed: 7 February 2026 (146f77)
Menu

Hyperf and Hypervel Integration

Purpose and Scope

This document explains how Telescope integrates with both the Hyperf and Hypervel frameworks through a dual-provider architecture. Telescope employs two distinct integration mechanisms: the ConfigProvider for low-level Hyperf dependency injection container integration, and the TelescopeServiceProvider for high-level Hypervel service registration and bootstrapping.

For information about package structure and dependencies, see Package Structure and Dependencies. For configuration options that control Telescope's behavior, see Configuration.


The Dual-Provider Architecture

Telescope uses two separate service providers to integrate with the framework stack:

ProviderFrameworkPurposeRegistration Method
ConfigProviderHyperfDI container bindings, aspect registrationextra.hyperf.config in composer.json
TelescopeServiceProviderHypervelService bootstrapping, route/command registrationextra.hypervel.providers in composer.json

This dual-provider pattern enables Telescope to leverage both Hyperf's infrastructure (dependency resolution, aspect-oriented programming) and Hypervel's higher-level abstractions (routing, console commands, service registration).

Registration Configuration

The composer.json36-47 file declares both providers in the extra section:


Sources: composer.json36-47


Hyperf Integration via ConfigProvider

ConfigProvider Role

The ConfigProvider class integrates Telescope with Hyperf's dependency injection container and aspect-oriented programming system. This provider is automatically discovered and loaded by Hyperf's configuration scanner during application bootstrap.

The ConfigProvider is responsible for:

  1. Dependency Injection Bindings: Registering contracts and their implementations in the DI container
  2. Aspect Registration: Enabling AOP-based method interception (see Aspects System)
  3. Configuration Publishing: Declaring publishable assets and migrations
  4. Dependency Declaration: Exposing required framework components

Integration Points with Hyperf Core


Sources: composer.json22-29


Hypervel Integration via TelescopeServiceProvider

TelescopeServiceProvider Role

The TelescopeServiceProvider extends Hypervel's ServiceProvider base class and orchestrates Telescope's high-level initialization within the Hypervel framework. This provider executes during Hypervel's service provider boot sequence.

The src/TelescopeServiceProvider.php18-180 class performs the following initialization tasks:

Registration Phase (register() method)

The register() method executes first and configures Telescope's foundation:

TaskLine ReferenceDescription
Configuration Mergingsrc/TelescopeServiceProvider.php114-117Merges config/telescope.php into application config
Storage Driver Registrationsrc/TelescopeServiceProvider.php119Binds repository contracts to implementations
Redis Eventssrc/TelescopeServiceProvider.php120Enables Redis command tracking if RedisWatcher is active
Cache Eventssrc/TelescopeServiceProvider.php121Enables cache operation tracking if CacheWatcher is active

Bootstrap Phase (boot() method)

The boot() method executes after all providers are registered and performs system activation:

TaskLine ReferenceDescription
Command Registrationsrc/TelescopeServiceProvider.php25Registers console commands (clear, pause, prune, publish, resume)
Publishing Configurationsrc/TelescopeServiceProvider.php26Declares publishable assets and migrations
Enabled Checksrc/TelescopeServiceProvider.php28-30Exits early if telescope.enabled is false
Route Registrationsrc/TelescopeServiceProvider.php32Registers Telescope UI routes
Resource Registrationsrc/TelescopeServiceProvider.php33Loads view templates
System Startsrc/TelescopeServiceProvider.php35Calls Telescope::start() to initialize watchers
Storage Listenerssrc/TelescopeServiceProvider.php36Registers storage opportunity listeners
Coroutine Context Setupsrc/TelescopeServiceProvider.php38-47Configures context propagation for child coroutines

Sources: src/TelescopeServiceProvider.php18-180


Service Provider Bootstrap Sequence

The following diagram illustrates the complete initialization sequence when Telescope boots within a Hypervel application:


Sources: src/TelescopeServiceProvider.php22-48 src/TelescopeServiceProvider.php112-122


Storage Driver Registration

Telescope uses a dynamic driver registration pattern to bind repository contracts to concrete implementations. The src/TelescopeServiceProvider.php151-158 method determines which storage driver to register based on configuration.

Database Driver Registration

The default database driver binds three repository contracts to DatabaseEntriesRepository:


The src/TelescopeServiceProvider.php163-179 method registers these bindings:

ContractImplementationPurpose
EntriesRepositoryDatabaseEntriesRepositoryCore storage operations (store, find, get)
ClearableRepositoryDatabaseEntriesRepositoryClear operation support
PrunableRepositoryDatabaseEntriesRepositoryPrune operation support

Sources: src/TelescopeServiceProvider.php151-179


Route Registration Integration

Telescope registers its web interface routes through Hypervel's Route facade. The src/TelescopeServiceProvider.php53-63 method configures the route group:

Route Configuration


The route registration reads configuration from config/telescope.php:

  • telescope.path: Base path for the UI (default: telescope)
  • telescope.middleware: Array of middleware to apply (typically includes authorization)

Sources: src/TelescopeServiceProvider.php53-63


Conditional Feature Registration

Telescope conditionally enables Redis and Cache event tracking based on watcher configuration. This prevents unnecessary overhead when watchers are disabled.

Redis Events Registration

The src/TelescopeServiceProvider.php127-134 method checks if RedisWatcher is enabled:


Cache Events Registration

The src/TelescopeServiceProvider.php139-146 method checks if CacheWatcher is enabled:


This pattern ensures that event listeners are only registered when their corresponding watchers are active, minimizing performance impact.

Sources: src/TelescopeServiceProvider.php127-146


Coroutine Context Propagation

A critical aspect of Telescope's Hyperf integration is proper context management across coroutines. Swoole's coroutine model creates child coroutines for asynchronous operations, and Telescope must ensure recording state propagates correctly.

Context Propagation Mechanism

The src/TelescopeServiceProvider.php38-47 method registers a coroutine lifecycle hook:


Propagated Context Keys

KeyDefault ValuePurpose
Telescope::SHOULD_RECORDfalseWhether recording is enabled for current request
Telescope::IS_RECORDINGfalseRe-entrancy guard to prevent infinite loops
Telescope::BATCH_IDnullUUID grouping entries from same request

The hook reads each key from the parent coroutine's context using Coroutine::parentId() and writes it to the child's context. This ensures that child coroutines inherit the recording state, allowing Telescope to track operations across asynchronous boundaries.

Sources: src/TelescopeServiceProvider.php38-47


Framework Component Dependencies

Telescope leverages multiple Hyperf components as declared in composer.json22-29:

Hyperf Components

ComponentVersionUsage
hyperf/context~3.1.0Request-scoped state management, coroutine-safe storage
hyperf/support~3.1.0Utility functions, string helpers, array manipulation
hyperf/stringable~3.1.0Fluent string manipulation for data formatting
hyperf/tappable~3.1.0Fluent interface pattern support
hyperf/collection~3.1.0Data collection operations, filtering, mapping

Hypervel Components

ComponentVersionUsage
hypervel/core^0.3Service provider base class, routing facade, console framework

Sources: composer.json22-29


Integration Summary


The dual-provider architecture ensures Telescope integrates seamlessly with both Hyperf's infrastructure layer (DI container, AOP) and Hypervel's application layer (routing, commands, views). This separation of concerns enables Telescope to leverage low-level framework capabilities while maintaining high-level developer ergonomics.

Sources: composer.json36-47 src/TelescopeServiceProvider.php18-180