Centum\Console
The Console component can be used to easily develop command line applications.
Application endpoints are treated as Centum\Console\Command
objects. These Commands contain all of the code and all of the metadata is stored in a Centum\Console\CommandMetadata
object.
Centum\Console\Application
extracts the command name from $argv
, finds the appropriate Command, and then executes the Command’s code.
Centum\Console\Application
implements Centum\Interfaces\Console\ApplicationInterface
.
Centum\Console\Application(
Centum\Interfaces\Container\ContainerInterface $container
);
public function getCommandMetadata(class-string<Centum\Interfaces\Console\CommandInterface> $commandClass): Centum\Console\CommandMetadata
public function addCommand(class-string<Centum\Interfaces\Console\CommandInterface> $commandClass): void
public function getCommands(): array<string, class-string<Centum\Interfaces\Console\CommandInterface>>
public function addExceptionHandler(class-string<Centum\Interfaces\Console\ExceptionHandlerInterface> $exceptionClass): void
public function handle(Centum\Interfaces\Console\TerminalInterface $terminal): int
Default Commands
The following code snippets assume that the console application will be stored in cli.php
.
Centum\Console\Command\ListCommand
Will list all registered Centum\Console\Command
objects:
php cli.php list
Centum\Console\Command\QueueConsumeCommand
Will take the next available Task from the Queue and consume it (see Queue docs):
php cli.php queue:consume