Download the PHP package beryllium/llama without Composer
On this page you can find all versions of the php package beryllium/llama. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download beryllium/llama
More information about beryllium/llama
Files in beryllium/llama
Package llama
Short Description Llama Commander lets you use anonymous functions as console commands via the Symfony Console Component.
License MIT
Informations about the package llama
Llama Commander
Llama Commander lets you use anonymous functions as console commands via the Symfony Console Component.
Why does it exist?
Llama Commander allows developers to define Symfony Console Commands inline instead of having to create a class for each command. When developers are using the Console in a microframework or no-framework context, they may benefit from this flexibility.
What is the spec?
The class LlamaCommand takes the following parameters:
- $name: The name for the command (optional on instantiation, but must be set in the constructor or via the ->setName() or ->configure() methods before the command can be invoked)
- $configurator: An optional callable function to configure the command. This can be used to set the Description, Options, and Arguments for the console command.
- $executor: The core logic for the console command. This callable will receive the input and return the output at the core of the console command being written.
- $interactor: An optional callable that defines user interaction logic.
- $initializer: An optional callable that initializes parameters before interaction and execution.
How do I use it?
When you initialize a new , you pass it at minimum a name (string) and an "Executor" lambda (callable) that determines what the command does. You can also pass it a Configurator, an Initializer, or an Interactor.
If your command needs to have options or arguments, you can specify an anonymous Configurator function for that:
If you want your code to be more precise, you can also typehint the main lambda. This will help your IDE give you hints about how to interact with $input and $output:
Combining the above examples, you would register the command with the console application like so:
And that's all for now. If you would like to learn more about how to use the Symfony Console Component, the Symfony website has a very helpful documentation page about it.