waffle-commons / console
Console component for Waffle framework.
0.1.0-beta0
2026-05-16 14:39 UTC
Requires
- php: ^8.5
- waffle-commons/contracts: 0.1.0-beta0
Requires (Dev)
- carthage-software/mago: ^1.0.0-rc
- cyclonedx/cyclonedx-php-composer: ^6.1
- php-mock/php-mock-phpunit: ^2.13
- phpunit/phpunit: ^12.0
- vimeo/psalm: ^6.13
This package is auto-updated.
Last update: 2026-05-16 15:44:46 UTC
README
Waffle Console Component
Release:
v0.1.0-beta0
A minimalist, zero-magic CLI runtime for the Waffle Framework (RFC-012). Commands are registered explicitly at boot โ no auto-discovery โ and resolve their dependencies through constructor injection.
๐ฆ Installation
composer require waffle-commons/console
๐งฑ Surface
| Class | Role |
|---|---|
Waffle\Commons\Console\ConsoleApplication |
final implementation of ConsoleApplicationInterface. Owns the command registry and the run loop. |
Waffle\Commons\Console\Command\AbstractCommand |
Base class โ implements CommandInterface with shared helpers. |
Waffle\Commons\Console\Command\CacheClearCommand |
cache:clear โ flushes the configured CacheInterface backend. |
Waffle\Commons\Console\Command\RouteListCommand |
route:list โ renders the compiled route table. |
Waffle\Commons\Console\Command\SecurityAuditCommand |
security:audit โ walks controllers and prints the resolved access ladder (#[Rule] / #[Voter]). |
Waffle\Commons\Console\Input\ArgvInput |
InputInterface implementation parsing argv. |
Waffle\Commons\Console\Output\StreamOutput |
Default OutputInterface writing to STDOUT / STDERR. |
Waffle\Commons\Console\Output\NullOutput |
Silent OutputInterface for tests / quiet runs. |
Waffle\Commons\Console\Exception\ConsoleException |
Base exception (implements ConsoleExceptionInterface). |
Waffle\Commons\Console\Exception\CommandNotFoundException |
Thrown when find($name) cannot resolve. |
Waffle\Commons\Console\Exception\InvalidArgumentException |
Thrown on invalid CLI argument shape. |
๐ Quick start
The exact signature of ConsoleApplication::__construct, verbatim from src/ConsoleApplication.php:
public function __construct( private readonly string $name = Constant::DEFAULT_APP_NAME, private readonly string $version = '0.0.0', private readonly OutputInterface $output = new StreamOutput(), ?array $argv = null, // null โ reads $_SERVER['argv'] ) { /* โฆ */ }
And the run loop:
use Waffle\Commons\Console\ConsoleApplication; use Waffle\Commons\Console\Command\CacheClearCommand; use Waffle\Commons\Console\Command\RouteListCommand; $app = new ConsoleApplication(name: 'Waffle', version: '0.1.0-beta0'); $app->add(new CacheClearCommand($cache)); $app->add(new RouteListCommand($router)); exit($app->run()); // argv read from constructor, returns int exit code
๐ช Public API
final class ConsoleApplication implements ConsoleApplicationInterface { public function getName(): string; public function getVersion(): string; public function add(CommandInterface $command): void; public function has(string $name): bool; public function find(string $name): CommandInterface; // throws CommandNotFoundException public function all(): array; public function run(): int; // returns ExitCode::*->value }
run():
- With no arguments, prints the available-commands listing and exits with
ExitCode::USAGE. - The built-in
listcommand name reprints the same listing withExitCode::SUCCESS. -v/-vv/-vvv/--verbose/--very-verbose/--debug/--quietflags adjust output verbosity viaOutputInterface::setVerbosity(Verbosity).- Dispatches to the resolved command's
execute(InputInterface, OutputInterface): int. ConsoleExceptionInterfaceand any otherThrowableare caught and returned asExitCode::FAILURE, with the message printed to stderr.
๐ PHP 8.5 features used
final class ConsoleApplication.- Constructor property promotion +
private readonlyon every dependency. - Default
OutputInterface $output = new StreamOutput()โ PHP 8.1new in initializers. enum ExitCode: intandenum Verbosity(from contracts) for typed exit codes / verbosity levels.- Typed constants via
Waffle\Commons\Contracts\Console\Constant.
๐งช Testing
docker exec -w /waffle-commons/console waffle-dev composer tests
๐ License
MIT โ see LICENSE.md.