Download the PHP package faslatam/consolekit without Composer
On this page you can find all versions of the php package faslatam/consolekit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package consolekit
ConsoleKit
PHP library to create command line utilities.
Example
In cli.php:
In the shell:
hello world!
More examples in example.php
Installation
The easiest way to install ConsoleKit is using Composer with the following requirement:
Alternatively, you can download the archive and add the src/ folder to PHP's include path:
Usage
Options parser
The default options parser parses an argv-like array. Items can be of the form:
- --key=value
- --key
- -a
- -ab (equivalent of -a -b)
When an option has no value, true will be used. If multiple key/value pairs
with the same key are specified, the "key" value will be an array containing all the values.
If "--" is detected, all folowing values will be treated as a single argument
Example: the string "-a -bc --longopt --key=value arg1 arg2 -- --any text" will produce the following two arrays:
Creating commands
Any callbacks can be a command. It will receive three parameters: the arguments array, the options array and the console object.
Commands can also be defined as classes. In this case, they must inherit from ConsoleKit\Command
and override the execute()
method.
The ConsoleKit\Command
class offers helper methods, check it out for more info.
Registering commands
Commands need to be registered in the console object using the addCommand()
method (or addCommands()
).
Notice that in the last example we have provided a second argument which is an alias for a command. As closures have no name, one must be specified.
The command name for functions is the same as the function name with underscores replaced by dashes (ie. my_command becomes my-command).
The command name for command classes is the short class name without the Command
suffix and "dashized" (ie. HelloWorldCommand becomes hello-world).
Running
Simply call the run()
method of the console object
Automatic help generation
The help command is automatically registered and provides help about available methods based on doc comments.
Check out example.php for example of available tags
Formating text
Colors
The ConsoleKit\Colors::colorize()
method provides an easy way to colorize a text.
Colors are defined as either a string or an integer (through constants of the Colors
class).
Available colors: black, red, green, yellow, blue, magenta, cyan, white.
Foreground colors are also available in a "bold" variant. Suffix the color name with "+bold" or use the OR bit operator with constants.
TextFormater
The ConsoleKit\TextFormater
class allows you to format text using the following options:
- indentation using
setIndent()
or the indent option - quoting using
setQuote()
or the quote option - foreground color using
setFgColor()
or the fgcolor option - background color using
setBgColor()
or the bgcolor option
Options can be defined using setOptions()
or as the first parameter of the constructor.
Widgets
Dialog
Used to interact with the user
Box
Wraps text in a box
Produces:
Progress bar
Displays a progress bar