VOOZH about

URL: https://deepwiki.com/hypervel/permission/5-framework-integration

⇱ Framework Integration | hypervel/permission | DeepWiki


Loading...
Menu

Framework Integration

Purpose and Scope

This page explains how the Hypervel Permission package integrates with the Hypervel/Hyperf framework ecosystem. It covers the package discovery mechanism, service registration through dependency injection, and asset publishing workflows. For detailed documentation of individual service providers and their configuration, see Service Providers and Configuration. For a complete reference of configuration options, see Configuration Reference.

Package Discovery Mechanism

The Hypervel Permission package uses two framework-specific discovery mechanisms defined in composer.json39-51:


The hyperf.config key registers the ConfigProvider class for Hyperf's dependency injection container, while the hypervel.providers array registers the PermissionServiceProvider for Hypervel's service provider bootstrapping.

Sources: composer.json39-51

Bootstrap Sequence

The following diagram shows how the framework discovers and initializes the permission package:


Bootstrap Order:

  1. Hyperf framework reads composer.json extra section during container initialization
  2. ConfigProvider is instantiated and its __invoke() method is called
  3. Hypervel framework registers PermissionServiceProvider
  4. PermissionServiceProvider::register() is called to merge default configuration
  5. PermissionServiceProvider::boot() is called to set up asset publishing

Sources: composer.json39-51 src/ConfigProvider.php12-36 src/PermissionServiceProvider.php11-38

Dependency Injection Configuration

The ConfigProvider class registers service bindings for the dependency injection container in src/ConfigProvider.php14-17:


This binding establishes that when any code requests the Factory contract interface, the container will resolve it to a PermissionManager instance. The PermissionManager is registered as a singleton by default in the Hyperf container, ensuring a single instance manages all permission-related operations throughout the request lifecycle.

Service Resolution:

ContractImplementationScope
Hypervel\Permission\Contracts\FactoryHypervel\Permission\PermissionManagerSingleton

Sources: src/ConfigProvider.php14-17

Console Command Registration

The package registers console commands in src/ConfigProvider.php18-20:


This registration makes the permission:show command available through the Hyperf console interface. The framework automatically discovers and loads this command during console application initialization.

Sources: src/ConfigProvider.php18-20

Asset Publishing System

The package defines two publishable asset groups that developers can copy to their application:

Configuration File Publishing

Configuration publishing is defined in both ConfigProvider and PermissionServiceProvider:

ConfigProvider Definition src/ConfigProvider.php22-27:


PermissionServiceProvider Definition src/PermissionServiceProvider.php29-31:


Migration File Publishing

ConfigProvider Definition src/ConfigProvider.php28-33:


PermissionServiceProvider Definition src/PermissionServiceProvider.php33-37:


Asset Publishing Flow


The dual registration in both ConfigProvider and PermissionServiceProvider ensures compatibility with both Hyperf's native publishing mechanism and Hypervel's extended publishing system.

Sources: src/ConfigProvider.php21-34 src/PermissionServiceProvider.php27-38

Configuration Merging

The PermissionServiceProvider merges the package's default configuration during the register() phase src/PermissionServiceProvider.php21-24:


This ensures that the package's default configuration values are available even before the developer publishes the configuration file. When a published configuration file exists, its values override the defaults.

Configuration Resolution Priority:

  1. Published configuration file at config/autoload/permission.php or config/permission.php
  2. Default configuration from package at publish/permission.php

Sources: src/PermissionServiceProvider.php19-25

Package Dependencies

The package declares framework dependencies in composer.json28-35:

DependencyVersionPurpose
hypervel/auth^0.3Authentication integration for middleware
hypervel/cache^0.3Caching system for permission lookups
hypervel/console^0.3Console command infrastructure
hypervel/core^0.3Core framework utilities
hypervel/support^0.3Service provider base class

These dependencies are automatically resolved by Composer and must be available for the permission package to function.

Sources: composer.json28-35

Service Provider Lifecycle

The following diagram shows the complete lifecycle of service provider methods:


Lifecycle Methods:

MethodPhasePurpose
ConfigProvider::__invoke()RegistrationRegister container bindings and commands
PermissionServiceProvider::register()RegistrationMerge default configuration
PermissionServiceProvider::boot()BootSet up asset publishing

Sources: src/ConfigProvider.php12-36 src/PermissionServiceProvider.php11-38

Integration Points Summary

The following table summarizes all integration points between the permission package and the Hypervel/Hyperf framework:

Integration PointMechanismFile LocationPurpose
Package Discoverycomposer.json extra sectioncomposer.json43-44Register ConfigProvider with Hyperf
Service Provider Registrationcomposer.json extra sectioncomposer.json46-49Register PermissionServiceProvider with Hypervel
Dependency InjectionConfigProvider dependencies arraysrc/ConfigProvider.php15-16Bind Factory interface to PermissionManager
Console CommandsConfigProvider commands arraysrc/ConfigProvider.php18-19Register ShowCommand
Configuration MergingServiceProvider mergeConfigFromsrc/PermissionServiceProvider.php21-24Load default configuration
Asset Publishing (Hyperf)ConfigProvider publish arraysrc/ConfigProvider.php21-34Define publishable config and migrations
Asset Publishing (Hypervel)ServiceProvider publishes methodsrc/PermissionServiceProvider.php29-37Define publishable config and migrations

Sources: composer.json39-51 src/ConfigProvider.php12-36 src/PermissionServiceProvider.php11-38