VOOZH about

URL: https://deepwiki.com/hypervel/foundation/5-console-command-system

⇱ Console Command System | hypervel/foundation | DeepWiki


Loading...
Last indexed: 7 February 2026 (101eff)
Menu

Console Command System

Purpose and Scope

The Console Command System provides the CLI interface for Hypervel applications. It handles command discovery, registration, execution, and scheduling through the Hypervel\Foundation\Console\Kernel class. The system discovers commands from multiple sources (directories, annotations, configuration, closures) and executes them through a Hypervel\Console\Application instance (the "Artisan" application).

This page provides an overview of the console system architecture and components. For detailed subsystem information, see:

Sources: src/Console/Kernel.php1-438 src/Console/Contracts/Kernel.php1-97

System Architecture

The console system is built around the Hypervel\Foundation\Console\Kernel class, which implements Hypervel\Foundation\Console\Contracts\Kernel. The kernel coordinates command discovery from multiple sources, registers them with a Hypervel\Console\Application instance, and manages the command execution lifecycle.

System Architecture

The console system is built around the Hypervel\Foundation\Console\Kernel class, which coordinates command discovery, registration, and execution. Commands can be defined through multiple mechanisms: class-based commands in directories, annotations, configuration arrays, command route files, and closure-based commands.

Console System Component Architecture


Sources: src/Console/Kernel.php32-438 src/Console/Contracts/Kernel.php13-97

Core Components

Console Kernel

The Hypervel\Foundation\Console\Kernel class serves as the central coordinator for the console system. It implements the Hypervel\Foundation\Console\Contracts\Kernel interface and manages the complete command lifecycle from discovery to execution.

ComponentTypeDescription
Kernel classMain implementationCentral console coordinator
$artisan propertyApplicationContractArtisan console application instance
$commands propertyarrayExplicitly registered command classes
$closureCommands propertyarrayClosure-based commands
$commandPaths propertyarrayDirectories for command auto-discovery
$commandRoutePaths propertyarrayCommand route files to load
$bootstrappers propertyarrayApplication bootstrapping classes

Sources: src/Console/Kernel.php32-76

Built-in Commands

The Foundation package provides several built-in commands registered through ConfigProvider. These commands are registered in the commands() method of the config provider, making them available to all Hypervel applications.

Command ClassSignatureDescription
AboutCommandaboutDisplay application information
ConfigShowCommandconfig:showDisplay configuration values
ServerReloadCommandserver:reloadReload all workers gracefully
VendorPublishCommandvendor:publishPublish vendor assets

These commands are automatically discovered and registered by Hyperf's command collection system through the config provider.

Sources: src/ConfigProvider.php31-36 </old_str>

<old_str>

Bootstrappers

The console kernel bootstraps the application before executing commands using three core bootstrapper classes:


The bootstrapper array is defined at src/Console/Kernel.php71-75 and executed during the bootstrap() method at src/Console/Kernel.php103-120

Sources: src/Console/Kernel.php71-75 src/Console/Kernel.php103-120 </old_str> <new_str>

Bootstrappers

The console kernel bootstraps the application before executing commands using three core bootstrapper classes defined in the $bootstrappers property:


The bootstrapper array is defined at src/Console/Kernel.php71-75 and executed during the bootstrap() method at src/Console/Kernel.php105-107 These are the same bootstrappers used by the HTTP kernel, ensuring consistent application initialization across both contexts.

Sources: src/Console/Kernel.php71-75 src/Console/Kernel.php103-120

Artisan Application

The console kernel creates and manages a Hypervel\Console\Application instance (the "Artisan" application), which is responsible for parsing input, finding commands, and executing them. This is accessed via the getArtisan() method.

Sources: src/Console/Kernel.php36 src/Console/Kernel.php402-417

Command Lifecycle

Console Command Execution Flow


Sources: src/Console/Kernel.php95-120 src/Console/Kernel.php149-214 src/Console/Kernel.php402-417 src/Console/Kernel.php434-437

Key Lifecycle Methods

MethodPurposeFile Reference
run()Execute the console applicationsrc/Console/Kernel.php434-437
handle()Process input/output through Artisansrc/Console/Kernel.php95-98
bootstrap()Initialize application for commandssrc/Console/Kernel.php103-120
discoverCommands()Auto-discover commands from pathssrc/Console/Kernel.php133-144
collectCommands()Gather commands from all sourcessrc/Console/Kernel.php149-192
loadCommands()Register collected commandssrc/Console/Kernel.php194-214
registerCommand()Add command to Artisan appsrc/Console/Kernel.php219-226

Sources: src/Console/Kernel.php95-226

Command Sources and Discovery

The console kernel discovers and collects commands from six distinct sources, which are then merged and registered with the Artisan application.

Command Collection Sources


Sources: src/Console/Kernel.php149-192

Discovery Configuration

Commands can be configured for automatic discovery through several kernel properties and methods:

Property/MethodTypeDescription
$commandPathsarrayDirectories to scan for command classes
$commandRoutePathsarrayPHP files containing command route definitions
addCommandPaths()methodAdd directories for command discovery
addCommandRoutePaths()methodAdd command route files
load()methodAdd paths to the loaded paths array

Sources: src/Console/Kernel.php49-56 src/Console/Kernel.php332-389

Command Registration Methods

Explicit Command Registration

Commands can be registered explicitly through the addCommands() method:

$kernel->addCommands([
 MyCommand::class,
 AnotherCommand::class,
]);

Sources: src/Console/Kernel.php360-369

Closure-Based Commands

The kernel supports registering commands using closures through the command() method:

$kernel->command('signature {argument}', function ($argument) {
 // Command implementation
});

This creates a Hypervel\Console\ClosureCommand instance, which is either immediately registered (if commands are already loaded) or stored in $closureCommands for later registration.

Sources: src/Console/Kernel.php311-327

Command Prioritization

When loading commands, the kernel ensures Hyperf framework commands are registered first, allowing application commands to override them:


Sources: src/Console/Kernel.php194-214

Command Sources and Discovery

The console kernel discovers and collects commands from six distinct sources, which are then merged and registered with the Artisan application.

Command Source Summary

SourceProperty/MethodDiscovery MechanismFile Reference
Loaded paths$loadedPaths via load()ReflectionManager::getAllClasses() scans directoriessrc/Console/Kernel.php152-155
Config arrayconfig('commands')ConfigInterface::get('commands', [])src/Console/Kernel.php158-160
Annotations@Command annotationsAnnotationCollector::getClassesByAnnotation()src/Console/Kernel.php163-169
Explicit commands$commands propertyDirect class name arraysrc/Console/Kernel.php41 src/Console/Kernel.php190
Closure commands$closureCommands propertyRegistered via command() methodsrc/Console/Kernel.php46 src/Console/Kernel.php183-187
Command paths$commandPaths propertyAuto-discovered during discoverCommands()src/Console/Kernel.php51 src/Console/Kernel.php135-137

Task Scheduling

The console kernel integrates with the Hypervel\Console\Scheduling\Schedule class to support scheduled task execution. The scheduling system is initialized during application boot.

Schedule Configuration


The schedule() method can be overridden in application kernels to define scheduled tasks:

protected function schedule(Schedule $schedule): void
{
 $schedule->command('emails:send')->daily();
}

Sources: src/Console/Kernel.php87-89 src/Console/Kernel.php257-299

Scheduling Methods

MethodPurposeFile Reference
schedule()Define scheduled tasks (override in subclasses)src/Console/Kernel.php257-259
resolveConsoleSchedule()Create Schedule instancesrc/Console/Kernel.php264-269
defineConsoleSchedule()Bind Schedule to containersrc/Console/Kernel.php274-281
scheduleTimezone()Get timezone for scheduled eventssrc/Console/Kernel.php286-291
scheduleCache()Get cache store for schedule mutexessrc/Console/Kernel.php296-299

Sources: src/Console/Kernel.php257-299

Integration with Application

The console kernel is tightly integrated with the application container and lifecycle:

Container Integration


Sources: src/Console/Kernel.php77-90 src/Console/Kernel.php402-417

Kernel Contract Methods

The Hypervel\Foundation\Console\Contracts\Kernel interface defines the public API for console kernel operations:

MethodReturn TypeDescription
bootstrap()voidBootstrap application for commands
schedule()voidDefine command schedule
commands()voidRegister application commands
command()ClosureCommandRegister closure-based command
load()voidAdd command discovery paths
addCommands()staticSet explicit commands
addCommandPaths()staticSet command discovery paths
addCommandRoutePaths()staticSet command route paths
getLoadedPaths()arrayGet loaded command paths
registerCommand()voidRegister single command
call()mixedExecute command by name
all()arrayGet all registered commands
output()stringGet output from last command
getArtisan()ApplicationContractGet Artisan instance
setArtisan()voidSet Artisan instance

Sources: src/Console/Contracts/Kernel.php13-97

Configuration Provider Registration

The ConfigProvider registers the console kernel's dependencies and built-in commands with Hyperf's dependency injection system:


Sources: src/ConfigProvider.php20-46