VOOZH about

URL: https://deepwiki.com/hypervel/devtool/3.1-command-registration-system

⇱ Command Registration System | hypervel/devtool | DeepWiki


Loading...
Menu

Command Registration System

Purpose and Overview

The Command Registration System is the core mechanism that makes all 30 commands available to the Hyperf framework through the ConfigProvider class. This system implements a fail-safe registration pattern that conditionally registers commands only when the required base dependency (Hyperf\Devtool\Generator\GeneratorCommand) is available, ensuring graceful degradation if dependencies are missing.

The ConfigProvider class located at src/ConfigProvider.php serves as the single registration point for:

  • 2 development utility commands (WatchCommand, EventListCommand)
  • 28 code generation commands (extending GeneratorCommand)

For information about the generator command architecture, see page 3.2. For the code generation system details, see page 4.

Sources: src/ConfigProvider.php1-82

ConfigProvider Class Structure

The Hypervel\Devtool\ConfigProvider class implements Hyperf's package discovery pattern through a single __invoke() method. This method is automatically called during application bootstrapping when Hyperf scans the composer.json file's extra.hyperf.config section.

Class Signature and Imports


Sources: src/ConfigProvider.php1-38

The class imports 30 command classes (lines 8-37) and one external base class for dependency checking (line 7). The namespace Hypervel\Devtool (line 5) indicates this is a Hypervel-specific extension.

Conditional Registration Logic

The __invoke() method implements a fail-safe pattern:


Sources: src/ConfigProvider.php41-81

The dependency check at src/ConfigProvider.php43-45 prevents fatal errors if the hyperf/devtool package is not installed or the GeneratorCommand base class is unavailable. This allows the package to be installed without breaking the application, though no commands will be available.

Return Structure

When dependencies are satisfied, the method returns an associative array with a commands key containing all 30 command class names:

Array KeyValue TypeDescription
commandsarray<int, class-string>Array of fully-qualified command class names

Sources: src/ConfigProvider.php47-80

Command Organization and Categories

The 30 commands registered in src/ConfigProvider.php48-79 are organized into functional categories. The registration order in the code does not follow these categories, but the logical grouping helps understand the package's scope.

Command Registration Order and Categories


Sources: src/ConfigProvider.php48-79

Category Distribution

CategoryCommand CountPrimary Purpose
Database Migrations7Generate framework infrastructure table migrations
HTTP Layer8Generate controllers, middleware, requests, resources, and related HTTP components
Event System6Generate events, listeners, jobs, notifications, and messaging components
Model System4Generate models, factories, seeders, and observers
Development Utilities2Development tools (watch, event inspection)
Authorization1Generate policy classes
Testing1Generate test cases
CLI1Generate console commands

Sources: src/ConfigProvider.php48-79

Registration Process Flow

The registration process integrates with Hyperf's package discovery and command loading mechanisms:

Discovery and Registration Sequence


Sources: src/ConfigProvider.php41-81

Integration Points

The registration system integrates with Hyperf through these key points:

Integration PointLocationMechanism
Package Discoverycomposer.jsonextra.hyperf.config field lists ConfigProvider
Provider InvocationBootstrap phaseHyperf calls ConfigProvider::__invoke()
Command ArrayReturn value['commands' => [class-string, ...]] structure
Dependency Checksrc/ConfigProvider.php43class_exists(GeneratorCommand::class)
Command InstantiationRuntimeDI container resolves command classes on demand

Sources: src/ConfigProvider.php41-81

Runtime Command Execution

When a developer executes a command (e.g., php bin/hyperf.php make:model User):


The command registry uses the class names registered by ConfigProvider to resolve command instances through the DI container.

Sources: src/ConfigProvider.php47-80

Complete Command Reference

All 30 commands registered by ConfigProvider are listed below with their registration line numbers and primary purposes:

Development Utilities (2 commands)

Command ClassLineCLI SignaturePurpose
WatchCommand49watchMonitors file changes and auto-restarts server
EventListCommand63event:listLists all registered events and their listeners

Database Migration Generators (7 commands)

Command ClassLineCLI SignaturePurpose
SessionTableCommand55make:session-tableGenerates session storage table migration
CacheTableCommand56make:cache-tableGenerates cache table migration
CacheLocksTableCommand57make:cache-locks-tableGenerates cache locks table migration
NotificationTableCommand65make:notifications-tableGenerates notification storage table migration
QueueTableCommand67make:queue-tableGenerates queue jobs table migration
QueueFailedTableCommand68make:queue-failed-tableGenerates failed jobs table migration
BatchesTableCommand66make:batches-tableGenerates job batches table migration

Model System Generators (4 commands)

Command ClassLineCLI SignaturePurpose
ModelCommand60make:modelGenerates model classes (can orchestrate factory, seeder, controller)
FactoryCommand61make:factoryGenerates model factory classes
SeederCommand62make:seederGenerates database seeder classes
ObserverCommand71make:observerGenerates model observer classes

HTTP Layer Generators (8 commands)

Command ClassLineCLI SignaturePurpose
ControllerCommand76make:controllerGenerates HTTP controller classes
MiddlewareCommand75make:middlewareGenerates middleware classes (standard/PSR-15)
RequestCommand64make:requestGenerates form request validation classes
ResourceCommand77make:resourceGenerates API resource transformer classes
ComponentCommand53make:componentGenerates view component classes
ProviderCommand50make:providerGenerates service provider classes
RuleCommand58make:ruleGenerates custom validation rule classes
ExceptionCommand78make:exceptionGenerates exception handler classes

Event System Generators (6 commands)

Command ClassLineCLI SignaturePurpose
EventCommand51make:eventGenerates event classes
ListenerCommand52make:listenerGenerates event listener classes
JobCommand69make:jobGenerates job classes for queue processing
ChannelCommand70make:channelGenerates broadcasting channel classes
NotificationCommand72make:notificationGenerates notification classes
MailCommand73make:mailGenerates mailable classes

Other Generators (3 commands)

Command ClassLineCLI SignaturePurpose
PolicyCommand74make:policyGenerates authorization policy classes
TestCommand54make:testGenerates test case classes
ConsoleCommand59make:commandGenerates custom console command classes

Sources: src/ConfigProvider.php48-79

Dependency Management

The ConfigProvider implements a defensive dependency check pattern to handle missing dependencies gracefully.

External Dependency: GeneratorCommand


Sources: src/ConfigProvider.php7-45

The dependency check at src/ConfigProvider.php43 uses class_exists(GeneratorCommand::class) to verify that the external base class from the hyperf/devtool package is available. This class is imported at src/ConfigProvider.php7

Fail-Safe Behavior

ConditionReturn ValueResult
GeneratorCommand exists['commands' => [...]]All 30 commands registered
GeneratorCommand missing[]Empty array, no commands registered

This pattern ensures that:

  1. The application doesn't crash if hyperf/devtool is not installed
  2. No fatal class-not-found errors occur during bootstrapping
  3. The package can be safely installed without breaking existing applications

Sources: src/ConfigProvider.php43-45

Summary

The Command Registration System is a critical foundation for the Hypervel Devtool package, making all code generation commands available to developers within a Hyperf application. Through the ConfigProvider class, approximately 24 different commands are registered, covering a wide range of application development needs from models and controllers to jobs, events, and database migrations.

This registration system demonstrates the integration capabilities of the Hyperf framework, allowing packages to seamlessly extend the framework's functionality while maintaining a consistent developer experience.

Sources: src/ConfigProvider.php33-70