Neuron-PHP

Application extends Base
in package

Comprehensive CLI application framework for the Neuron ecosystem.

This class serves as the central command-line interface for all Neuron framework components, providing unified command discovery, registration, execution, and management. It extends the base application framework to provide CLI-specific functionality with automatic component loading and modern command pattern implementation.

Key features:

  • Automatic component discovery and command registration
  • Extensible command registry with namespace support
  • Rich console I/O with formatting and progress indicators
  • Global option handling (--help, --version, --verbose)
  • Error handling with detailed debugging information
  • Exit code management for scripting integration
  • Component isolation and lazy loading

The application supports both core framework commands and component-specific commands, enabling a unified CLI experience across all Neuron modules. Commands are automatically discovered from installed components and registered with namespace prefixes (e.g., cms:init, mvc:routes).

Tags
example
// Basic CLI application setup
$app = new Application('1.0.0');

// Register custom command
$app->register('deploy:staging', DeployStagingCommand::class);

// Run the application
$app->run();

// Get exit code for scripting
exit($app->getExitCode());

Table of Contents

Properties

$_crashed  : bool
$_handleErrors  : bool
$_handleFatal  : bool
$_parameters  : array<string|int, mixed>
$_settings  : SettingManager|null
$_version  : string
$_basePath  : string
$_eventListenersPath  : string
$_registry  : Registry|null
$argv  : array<string|int, mixed>
$commandName  : string
$commandRegistry  : Registry
$componentLoader  : ComponentLoader
$currentCommand  : Command|null
$input  : Input
$output  : Output

Methods

__construct()  : mixed
Initial setup for the application.
beautifyException()  : string
Format exception/error for display Base implementation outputs plain text (CLI-friendly) MVC Application overrides this for HTML output
fatalHandler()  : void
Handler for fatal errors.
getBasePath()  : string
getCrashed()  : bool
getCurrentCommand()  : Command|null
Get the current command being executed
getEventListenersPath()  : string
getExitCode()  : int
Get the exit code from the last command execution
getParameter()  : mixed
Gets a parameter by name.
getParameters()  : array<string|int, mixed>
returns parameters passed to the run method.
getRegistry()  : Registry
Get the command registry
getRegistryObject()  : mixed
getSetting()  : mixed
getSettingManager()  : SettingManager|null
getVersion()  : string
Application version number.
globalExceptionHandler()  : void
Global exception handler for uncaught exceptions and errors Handles both Exception and Error (PHP 7+)
has()  : bool
Check if a command exists
initEvents()  : void
Loads event-listeners.yaml and maps all event listeners to their associated events.
initLogger()  : void
Initializes the logger based on the parameters set in neuron.yaml.
isCommandLine()  : bool
Returns true if the application is running in command line mode.
phpErrorHandler()  : bool
Handler for PHP errors.
register()  : void
Register a command with the CLI application
run()  : bool
Call to run the application.
setBasePath()  : Base
setEventListenersPath()  : Base
setHandleErrors()  : Base
setHandleFatal()  : Base
setRegistryObject()  : mixed
setSetting()  : void
setSettingSource()  : $this
willHandleErrors()  : bool
willHandleFatal()  : bool
executeCommand()  : void
Execute the specified command
executeInitializers()  : void
Executes all initializer classes located in app/Initializers.
formatFatalError()  : string
Format fatal error for display Uses HTML for web, plain text for CLI
initErrorHandlers()  : void
Sets up the php error and fatal handlers.
initSettings()  : void
onCrash()  : void
Called by the fatal handler if invoked.
onError()  : bool
Called for any unhandled exceptions.
onFinish()  : void
Called immediately after onRun.
onRun()  : void
Main execution of the CLI application
onStart()  : bool
Initialize the CLI application before run
registerCoreCommands()  : void
Register core commands that are always available
showCommandHelp()  : void
Show help for a specific command
showHelp()  : void
Show general help information
showVersion()  : void
Show version information

Properties

$_crashed

protected bool $_crashed = false

$_handleErrors

protected bool $_handleErrors = false

$_handleFatal

protected bool $_handleFatal = false

$_parameters

protected array<string|int, mixed> $_parameters

$_version

protected string $_version

$_basePath

private string $_basePath

$_eventListenersPath

private string $_eventListenersPath

Methods

__construct()

Initial setup for the application.

public __construct(string $version[, ISettingSource|null $source = null ]) : mixed
Parameters
$version : string
$source : ISettingSource|null = null
Tags
throws
Exception

beautifyException()

Format exception/error for display Base implementation outputs plain text (CLI-friendly) MVC Application overrides this for HTML output

public static beautifyException(Throwable $throwable) : string
Parameters
$throwable : Throwable
Return values
string

fatalHandler()

Handler for fatal errors.

public fatalHandler() : void

Checks for actual fatal errors and formats them for display

getBasePath()

public getBasePath() : string
Return values
string

getCrashed()

public getCrashed() : bool
Return values
bool

getCurrentCommand()

Get the current command being executed

public getCurrentCommand() : Command|null
Return values
Command|null

getEventListenersPath()

public getEventListenersPath() : string
Return values
string

getExitCode()

Get the exit code from the last command execution

public getExitCode() : int
Return values
int

getParameter()

Gets a parameter by name.

public getParameter(string $name) : mixed
Parameters
$name : string

getParameters()

returns parameters passed to the run method.

public getParameters() : array<string|int, mixed>
Return values
array<string|int, mixed>

getRegistryObject()

public getRegistryObject(string $name) : mixed
Parameters
$name : string

getSetting()

public getSetting(string $section, string $name) : mixed
Parameters
$section : string
$name : string

getVersion()

Application version number.

public getVersion() : string
Return values
string

globalExceptionHandler()

Global exception handler for uncaught exceptions and errors Handles both Exception and Error (PHP 7+)

public globalExceptionHandler(Throwable $throwable) : void
Parameters
$throwable : Throwable

has()

Check if a command exists

public has(string $name) : bool
Parameters
$name : string
Return values
bool

initEvents()

Loads event-listeners.yaml and maps all event listeners to their associated events.

public initEvents() : void

initLogger()

Initializes the logger based on the parameters set in neuron.yaml.

public initLogger() : void

destination format file level

Tags
throws
Exception

isCommandLine()

Returns true if the application is running in command line mode.

public isCommandLine() : bool
Return values
bool

phpErrorHandler()

Handler for PHP errors.

public phpErrorHandler(int $errorNo, string $message, string $file, int $line) : bool
Parameters
$errorNo : int
$message : string
$file : string
$line : int
Return values
bool

register()

Register a command with the CLI application

public register(string $name, string $class) : void
Parameters
$name : string

Command name (e.g., 'cms:init')

$class : string

Fully qualified class name of the command

run()

Call to run the application.

public run([array<string|int, mixed> $argv = [] ]) : bool
Parameters
$argv : array<string|int, mixed> = []
Tags
throws
Exception
Return values
bool

setBasePath()

public setBasePath(string $basePath) : Base
Parameters
$basePath : string
Return values
Base

setEventListenersPath()

public setEventListenersPath(string $eventListenersPath) : Base
Parameters
$eventListenersPath : string
Return values
Base

setHandleErrors()

public setHandleErrors(bool $handleErrors) : Base
Parameters
$handleErrors : bool
Return values
Base

setHandleFatal()

public setHandleFatal(bool $handleFatal) : Base
Parameters
$handleFatal : bool
Return values
Base

setRegistryObject()

public setRegistryObject(string $name, mixed $object) : mixed
Parameters
$name : string
$object : mixed

setSetting()

public setSetting(string $section, string $name, string $value) : void
Parameters
$section : string
$name : string
$value : string

willHandleErrors()

public willHandleErrors() : bool
Return values
bool

willHandleFatal()

public willHandleFatal() : bool
Return values
bool

executeCommand()

Execute the specified command

protected executeCommand() : void

executeInitializers()

Executes all initializer classes located in app/Initializers.

protected executeInitializers() : void

formatFatalError()

Format fatal error for display Uses HTML for web, plain text for CLI

protected formatFatalError(string $type, string $message, string $file, int $line) : string
Parameters
$type : string
$message : string
$file : string
$line : int
Return values
string

initErrorHandlers()

Sets up the php error and fatal handlers.

protected initErrorHandlers() : void

onCrash()

Called by the fatal handler if invoked.

protected onCrash(array<string|int, mixed> $error) : void
Parameters
$error : array<string|int, mixed>

onError()

Called for any unhandled exceptions.

protected onError(string $message) : bool

Returning false skips executing onFinish.

Parameters
$message : string
Return values
bool

onFinish()

Called immediately after onRun.

protected onFinish() : void

onRun()

Main execution of the CLI application

protected onRun() : void

onStart()

Initialize the CLI application before run

protected onStart() : bool
Return values
bool

registerCoreCommands()

Register core commands that are always available

private registerCoreCommands() : void

showCommandHelp()

Show help for a specific command

private showCommandHelp(string $commandName) : void
Parameters
$commandName : string

showHelp()

Show general help information

private showHelp() : void

showVersion()

Show version information

private showVersion() : void

        
On this page

Search results