VOOZH about

URL: https://deepwiki.com/hypervel/permission/5.1-service-providers-and-configuration

⇱ Service Providers and Configuration | hypervel/permission | DeepWiki


Loading...
Menu

Service Providers and Configuration

This document explains how the Hypervel Permission package integrates with the Hypervel/Hyperf framework through service providers. It covers the registration of dependencies, commands, and publishable assets, as well as the bootstrap lifecycle.

For details about the configuration options themselves, see Configuration Reference. For information about the runtime behavior of the PermissionManager service, see Permission Manager.


Overview of Service Providers

The package uses two service providers to integrate with the framework:

Service ProviderPurposeRegistration Method
ConfigProviderDeclares dependencies, commands, and publishable assets for framework auto-discoveryAuto-discovered by Hyperf
PermissionServiceProviderMerges configuration and publishes assets using Hypervel helpersManually registered in Hypervel applications

The ConfigProvider follows Hyperf conventions and is automatically discovered when the package is installed. The PermissionServiceProvider extends Hypervel\Support\ServiceProvider and provides Laravel-style asset publishing capabilities.

Sources: src/ConfigProvider.php1-37 src/PermissionServiceProvider.php1-39


ConfigProvider

The ConfigProvider class implements Hyperf's configuration provider pattern. It returns an array that declares what the package provides to the framework.

Structure


Diagram: ConfigProvider Structure and Declarations

Sources: src/ConfigProvider.php12-36

Dependency Registration

The dependencies array maps the Factory contract to the PermissionManager implementation:


This tells the dependency injection container to inject PermissionManager whenever Factory is type-hinted. The PermissionManager is resolved as a singleton, ensuring a single instance manages all permission operations across the application.

Sources: src/ConfigProvider.php15-17

Command Registration

The commands array registers console commands:


This makes the permission:show command available in the Hyperf console. For details about this command, see Console Commands.

Sources: src/ConfigProvider.php18-20

Publishable Assets

The publish array declares two types of assets that can be published to the application:

Asset IDDescriptionSourceDestination
configConfiguration filepublish/permission.phpconfig/autoload/permission.php
migrationsDatabase migrationdatabase/migrations/2025_07_02_000000_create_permission_tables.phpdatabase/migrations/2025_07_02_000000_create_permission_tables.php

Users can publish these assets using Hyperf's vendor publish commands:


Sources: src/ConfigProvider.php21-34


PermissionServiceProvider

The PermissionServiceProvider extends Hypervel\Support\ServiceProvider and provides Laravel-style service provider functionality for Hypervel applications.

Lifecycle Methods


Diagram: PermissionServiceProvider Lifecycle

Sources: src/PermissionServiceProvider.php11-38

Configuration Merging

The register() method merges the package's default configuration with the application's published configuration:


This ensures that:

  1. Package defaults are available even if the config file hasn't been published
  2. Published config values override package defaults
  3. The configuration is available under the permission key

Sources: src/PermissionServiceProvider.php19-25

Asset Publishing

The registerPublishing() method registers publishable assets with tags, allowing users to publish specific asset types:


This enables selective publishing:


Sources: src/PermissionServiceProvider.php27-38


Bootstrap Lifecycle

The following diagram shows how the service providers integrate into the framework bootstrap sequence:


Diagram: Complete Bootstrap Lifecycle

Sources: src/ConfigProvider.php1-37 src/PermissionServiceProvider.php1-39


Key Integration Points

Dependency Injection

The binding of Factory::class to PermissionManager::class allows other components to depend on the contract rather than the concrete implementation:


This abstraction enables testing and potential alternative implementations.

Sources: src/ConfigProvider.php15-17

Configuration Access

After the service provider merges the configuration, it's accessible throughout the application:


For a complete reference of all configuration options, see Configuration Reference.

Sources: src/PermissionServiceProvider.php21-24

Asset Publishing Workflow


Diagram: Asset Publishing Workflow

Sources: src/PermissionServiceProvider.php27-38


Comparison with Other Frameworks

The dual service provider approach supports both Hyperf and Hypervel (Laravel-like) patterns:

FeatureConfigProviderPermissionServiceProvider
FrameworkHyperfHypervel
Auto-discoveryYesNo (manual registration)
DI registrationYes (dependencies key)No
Command registrationYes (commands key)No
Config mergingNoYes (mergeConfigFrom)
Asset publishingDeclaration only (publish key)Full support (publishes method)
Helper methodsNoYes (inherited from ServiceProvider)

This design allows the package to work seamlessly in both pure Hyperf applications (using ConfigProvider alone) and Hypervel applications (using both providers).

Sources: src/ConfigProvider.php10-37 src/PermissionServiceProvider.php9-39


Summary

The service provider architecture integrates the Hypervel Permission package into the framework through:

  1. ConfigProvider - Auto-discovered by Hyperf, declares dependencies and publishables
  2. PermissionServiceProvider - Extends Hypervel's service provider base, merges config and enables asset publishing
  3. Dependency Injection - Binds Factory contract to PermissionManager singleton
  4. Asset Publishing - Provides config and migrations with selective publishing via tags
  5. Bootstrap Lifecycle - Follows framework conventions for proper initialization order

The PermissionManager singleton registered through these providers becomes available throughout the application, providing centralized permission and role management. For details about how this manager operates, see Permission Manager.

Sources: src/ConfigProvider.php1-37 src/PermissionServiceProvider.php1-39