Download the PHP package weebel/console without Composer
On this page you can find all versions of the php package weebel/console. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download weebel/console
More information about weebel/console
Files in weebel/console
Package console
Short Description PHP console kernel with built-in command handling for CLI applications
License MIT
Informations about the package console
Weebel Console
A simple and flexible console package for PHP that lets you build command-line applications with ease.
Installation
The easiest way to install the package is through composer:
Usage
To utilize the console kernel, you must have a container class that implements the Psr\Container\ContainerInterface
interface. A popular example of this is the Laravel container. Here is a simple usage example of this package using the Laravel container in the main bootstrap executable file in the project (you may name the file as console in the bin directory of your project):
In the example above, we first include the autoload file to bring in all the necessary dependencies. Then, we retrieve the CommandContainer instance, and register the ExampleCommand class with it. Finally, we create an instance of the container and pass it to the ConsoleKernelBooter
class to start the console application.
Creating Commands
To create a command, extend the Weebel\Console\Command
class and add a unique name constant and a description constant for the command. You can also specify the valid options for the command by defining the $validOptions property as an array.
Here's an example of a greeting command:
After registering your command, you can execute it using the following syntax in the terminal:
Customizing the Console Output
The package provides a HasClimate
trait, which can be used to customize the console output. You can use this trait in your commands to add colors, formatting and other customizations to the output.
Here are a few examples of how you can use the HasClimate trait to customize the console output:
-
To add colors:
-
To format text:
-
To display messages with tabs
- To display messages with line breaks
With the HasClimate
trait, you have full control over the way the console output is displayed, allowing you to create visually appealing and easy-to-read outputs.
Extending the functionality
The package provides a way to extend its functionality by allowing you to create listeners for the events it triggers. One such event is the CommandResolved
event which is triggered when a command has been resolved from the input. This event provides information about the resolved command and its options.
- In order to use this functionality you need to pass your EventDispatcher implementation to the kernel booter. Your event dispatcher should implement
Psr\EventDispatcher\EventDispatcherInterface
.
Here is an example of using the popular Symfony event dispatcher in the console kernel:
License
Weebel Console is open-source software licensed under the MIT license.