Console component for Waffle framework.

Maintainers

Package info

github.com/waffle-commons/console

pkg:composer/waffle-commons/console

Statistics

Installs: 2

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0-beta0 2026-05-16 14:39 UTC

This package is auto-updated.

Last update: 2026-05-16 15:44:46 UTC


README

PHP Version Require PHP CI codecov Latest Stable Version Latest Unstable Version Total Downloads Packagist License

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():

  1. With no arguments, prints the available-commands listing and exits with ExitCode::USAGE.
  2. The built-in list command name reprints the same listing with ExitCode::SUCCESS.
  3. -v / -vv / -vvv / --verbose / --very-verbose / --debug / --quiet flags adjust output verbosity via OutputInterface::setVerbosity(Verbosity).
  4. Dispatches to the resolved command's execute(InputInterface, OutputInterface): int.
  5. ConsoleExceptionInterface and any other Throwable are caught and returned as ExitCode::FAILURE, with the message printed to stderr.

๐Ÿ˜ PHP 8.5 features used

  • final class ConsoleApplication.
  • Constructor property promotion + private readonly on every dependency.
  • Default OutputInterface $output = new StreamOutput() โ€” PHP 8.1 new in initializers.
  • enum ExitCode: int and enum 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.