pmjones/caplet
Caplet is a minimal PSR-11 autowiring dependency injection container for constructor injection and simple factories. Use get() for shared instances, new() for fresh ones, configure scalar parameters via an array, and map interfaces/abstracts via factories.
Start by requiring the package via Composer:
composer require pmjones/caplet
Then create a new Caplet instance and add commands using addCommand(). Each command is a closure or invokable object implementing the Caplet\Command interface (typically with __invoke(Input $input, Output $output)). The basic pattern:
use Caplet\Caplet;
use Caplet\Input;
use Caplet\Output;
$caplet = new Caplet();
$caplet->addCommand('hello', function (Input $input, Output $output) {
$name = $input->getArgument('name') ?? 'World';
$output->writeln("Hello, {$name}!");
});
$caplet->run();
Run it from CLI: php your-script.php hello --name=Taylor. Use --help to see auto-generated usage.
build, test, deploy). Each command handles one task cleanly.$input->getArgument(), $input->getOption(), and $input->hasOption() to extract CLI parameters. Define argument/option defaults in the command or at registration via addCommand('cmd', $callback, ['arguments' => [...], 'options' => [...]]).Output (with methods like write(), writeln(), error()) instead of echoing directly. For unit tests, use Output\Buffer or Output\Null to capture or suppress output.db:migrate, db:seed) using a top-level Caplet and nested registration.0 for success, 1 for error); Caplet honors this.fn($in, $out) => (new MyCommand($service))->run($in, $out)).Output interface does not auto-flush; to force immediate output (e.g., progress bars), call $output->flush().$output->error('Invalid option') and return 1.$caplet->run(); dynamic commands added mid-execution won’t appear in help.Output\Stream with a decorator (e.g., add ANSI escape codes via helper methods in your Output subclass).Input/Output to support such features.How can I help you explore Laravel packages today?