hierone/console

A modern, feature-rich PHP console application framework with dependency injection, styling, and extensibility.

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/hierone/console

v1.0.0 2025-10-09 10:14 UTC

This package is auto-updated.

Last update: 2025-10-09 10:17:57 UTC


README

A modern, powerful, and production-ready console component for building beautiful and testable command-line interfaces in PHP 8.2+.

Features

  • Modern PHP 8.2+: Uses PHP 8+ attributes for command definition
  • Dependency Injection: Full integration with Hierone Injector component
  • Auto-Discovery: Automatic command discovery via attributes and namespaces
  • Event System: Extensible event-driven architecture for command lifecycle
  • Rich Output: Styled output with colors, formatting, and ANSI support
  • Built-in Commands: Help, list, completion, and debug commands included
  • Robust Exception Handling: Comprehensive error handling with user-friendly messages and smart command suggestions
  • Advanced Input Parsing: Reliable argument and option parsing with full validation
  • Testing Support: Complete test suite with helper classes and fixtures - 100% test coverage achieved
  • Production Ready: Thoroughly tested and debugged for real-world usage

Quick Start

Basic Usage

use Hierone\Component\Console\Application;
use Hierone\Component\Console\Command\Command;
use Hierone\Component\Console\Input\InputInterface;
use Hierone\Component\Console\Output\OutputInterface;

// Create application
$app = new Application('My App', '1.0.0');

// Add a simple command
$app->add(new class('greet') extends Command {
    public function configure(): void
    {
        $this->setDescription('Greet someone')
             ->addArgument('name', InputArgument::REQUIRED, 'Who to greet');
    }
    
    public function execute(InputInterface $input, OutputInterface $output): int
    {
        $name = $input->getArgument('name');
        $output->writeln("Hello, {$name}!");
        return Command::SUCCESS;
    }
});

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

Using Attributes (Recommended)

use Hierone\Component\Console\Attribute\AsCommand;
use Hierone\Component\Console\Attribute\Argument;
use Hierone\Component\Console\Command\Command;

#[AsCommand(
    name: 'greet',
    description: 'Greet someone',
    aliases: ['hello']
)]
class GreetCommand extends Command
{
    #[Argument(
        name: 'name',
        description: 'Who to greet',
        required: true
    )]
    private string $name;

    public function execute(InputInterface $input, OutputInterface $output): int
    {
        $output->writeln("<info>Hello, {$this->name}!</info>");
        return Command::SUCCESS;
    }
}

// Auto-discover commands
$app->discoverCommands(__DIR__ . '/Commands', 'App\\Commands');

Installation

composer require hierone/console

Documentation

Command Creation

  • Use PHP 8+ attributes for modern command definition
  • Extend the base Command class
  • Implement execute() method for command logic

Input Handling

  • Arguments: Required or optional positional parameters
  • Options: Named parameters with values or flags
  • Automatic validation and type conversion

Output Formatting

  • Colored and styled output with tags: <info>, <error>, <comment>
  • Custom styles and formatting
  • Verbosity levels and quiet mode

Event System

  • Hook into command lifecycle with events
  • Extensible architecture for custom behavior
  • Built-in logging and debugging support

Testing

  • Comprehensive test utilities included
  • Mock commands and buffered output
  • PHPUnit integration examples

License

This component is part of the Hierone Package and is licensed under the MIT License.