Download the PHP package meritum/cli without Composer
On this page you can find all versions of the php package meritum/cli. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package cli
Short Description Module-first console kernel for the Meritum ecosystem
License MIT
Informations about the package cli
meritum/cli
Module-first console kernel (Sage) for the Meritum ecosystem. Wraps symfony/console with a clean bootstrapping API — constructor injection for dependencies, fluent builders for command definitions, and the same kernel lifecycle as meritum/http.
Requirements
- PHP 8.4+
- georgeff/kernel ^1.6
- symfony/console ^8.1
Installation
Bootstrapping
Create an entry point (e.g. bin/console):
Customising the application name and version
These must be set before boot().
Registering Commands
Commands are registered via the kernel's container using the cli.commands tag. The CliKernelOption enum holds the tag name:
Commands are resolved from the container at dispatch time, so all dependencies are injected via the constructor.
Writing Commands
Extend Meritum\Cli\Command\Command and implement __invoke:
The constructor is reserved for real dependencies. All command metadata (name, description, arguments, options) is configured in the factory definition.
Reading Input
SageStyleInterface exposes helpers for reading arguments and options:
Arguments
Options
Calling Commands from Commands
A command can invoke another command via call(). The kernel must be initialised (i.e. the command must be registered and the kernel booted) for this to work:
If no output is passed, the sub-command's output is discarded. The return value is the sub-command's exit code.
call() resolves the target command directly via CliKernelInterface::find() and runs it — it does not re-dispatch through the full Application. If no command matches the given name or alias, it throws Meritum\Cli\Exception\CommandNotFoundException.
Finding Commands
CliKernelInterface::find(string $command): ?CommandInterface looks up a registered command by name or alias, returning null if none match:
The kernel must be booted before calling find().
Exception Handling
Register an ExceptionHandlerInterface implementation to catch unhandled exceptions thrown during dispatch. Without one, exceptions propagate to the caller.
Register it in the kernel before boot:
The kernel returns ExitCode::Error (1) when the exception handler is invoked.
Kernel Lifecycle
CliKernel follows the standard georgeff/kernel lifecycle:
handle() requires the kernel to be booted and not shutdown. run() calls handle() and must also be called on a live kernel.
Modules
Commands and services can be packaged into reusable modules: