mnapoli/silly
Silly is a lightweight CLI micro-framework built on Symfony Console. Define commands with simple signatures and PHP callables, get options/arguments parsing, helpers, and DI integration (PHP-DI or Pimple) while staying compatible with Symfony Console apps.
A command can be any PHP callable:
// Closure
$app->command('foo', function () {
// ...
});
// An object implementing __invoke()
$app->command('foo', new InvokableObject());
// An object method
$app->command('foo', [$object, 'method']);
// A static class method
$app->command('foo', ['MyClass', 'method']);
// A function
$app->command('foo', 'someFunction');
The callable can take as parameters the arguments and options defined in the expression:
$app->command('greet name [--yell]', function ($name, $yell) {
// ...
});
The order of parameters doesn't matter as they are always matched by name.
When running $ bin/console greet john --yell:
$name will be 'john'$yell will be trueYou can also ask for the $input and $output parameters to get the traditional Symfony InputInterface and OutputInterface objects (the type-hint is optional):
$app->command(
'greet name [--yell]',
function (InputInterface $input, OutputInterface $output) {
$name = $input->getArgument('name');
$yell = $input->getOption('yell');
// ...
}
);
You can also inject the SymfonyStyle object by type-hinting it:
use \Symfony\Component\Console\Style\SymfonyStyle;
...
$app->command('greet', function (SymfonyStyle $io) {
$io->write('hello');
});
Finally, you can mix all that (remember the order of parameters doesn't matter):
$app->command(
'greet name [--yell]',
function ($name, InputInterface $input, OutputInterface $output) {
// ...
}
);
It is also possible to set up dependency injection through the callables parameters. To learn more about that, read the Dependency injection documentation.
How can I help you explore Laravel packages today?