A lightweight PHP command-line interface (CLI) framework for building modular, easy-to-use console applications.
- Simple Command Structure: Create commands by extending a base class with a
handle()method - Automatic Command Loading: Commands are auto-discovered from the
Commands/directory - Nested Subcommands: Organize commands in subdirectories (e.g.,
user:create,user:list) - Argument Parsing: Built-in support for named arguments (
--key=value) - Colored Output: Beautiful terminal output with color support (green, red, yellow, blue)
- Logging: Automatic logging of all command executions to
logs/app.log - Helper Functions: Utility methods for user interaction (pause, clear screen, etc.)
- Clone or download this repository
- Ensure PHP 7.4+ is installed
- No external dependencies required!
# View all available commands
php zap help
# Run a command
php zap greet
# Run a command with arguments
php zap sum --a=5 --b=3
# Run a nested subcommand
php zap user:create
php zap user:listCreate a file in src/Commands/ named YourNameCommand.php:
<?php
namespace App\Commands;
use App\Helpers;
class YourNameCommand
{
public static string $description = "Description of what this command does";
public static function handle(array $args): void
{
Helpers::info("Command started");
Helpers::success("Success message");
Helpers::error("Error message");
Helpers::warn("Warning message");
}
}The command will be automatically registered as php zap yourname.
Create a subdirectory in src/Commands/ and add commands inside:
src/Commands/
├── User/
│ ├── CreateCommand.php → php zap user:create
│ └── ListCommand.php → php zap user:list
The Helpers class provides useful utilities:
use App\Helpers;
// Output with colors
Helpers::println("Text", 'green'); // Green text
Helpers::println("Text", 'red'); // Red text
Helpers::println("Text", 'yellow'); // Yellow text
Helpers::println("Text", 'blue'); // Blue text
// Status messages (auto-logged)
Helpers::success("Operation completed"); // ✔ Green
Helpers::error("Something went wrong"); // ✖ Red
Helpers::info("Information"); // ℹ Blue
Helpers::warn("Warning"); // ! Yellow
// User interaction
Helpers::pause(); // Wait for Enter key
Helpers::clearScreen(); // Clear terminal
Helpers::line(); // Print separator line
// Argument parsing
$args = Helpers::parseArgs($input);
// Logging
Helpers::log("Message", 'INFO');
Helpers::log("Error occurred", 'ERROR');cnsl/
├── zap # Entry point script
├── README.md # This file
├── .gitignore # Git ignore rules
├── logs/ # Application logs (auto-created)
└── src/
├── Zap.php # Main CLI framework
├── Helpers.php # Utility functions
└── Commands/ # Your commands go here
├── GreetCommand.php
├── SumCommand.php
└── User/
├── CreateCommand.php
└── ListCommand.php
- Entry Point:
php zaploads thezapfile - Autoloading: PSR-4 autoloader in
zapfile loads classes fromsrc/ - Command Discovery:
Helpers::loadCommands()scanssrc/Commands/for*Command.phpfiles - Execution: The framework parses arguments and calls the command's
handle()method - Logging: All operations are logged to
logs/app.log
Arguments are passed using the --key=value format:
php zap sum --a=10 --b=20Inside your command:
public static function handle(array $args): void
{
$a = $args['a'] ?? 0; // Access as associative array
$b = $args['b'] ?? 0;
echo $a + $b;
}All messages logged via Helpers::log(), Helpers::success(), Helpers::error(), Helpers::info(), and Helpers::warn() are automatically written to logs/app.log with timestamps and log levels.
MIT