Download the PHP package splitbrain/php-cli without Composer

On this page you can find all versions of the php package splitbrain/php-cli. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-cli

PHP-CLI

PHP-CLI is a simple library that helps with creating nice looking command line scripts.

It takes care of

It is lightweight and has no 3rd party dependencies. Note: this is for non-interactive scripts only. It has no readline or similar support.

Installation

Use composer:

Usage and Examples

Minimal example:

The basic usage is simple:

More examples can be found in the examples directory. Please refer to the API docs for further info.

Exceptions

By default, the CLI class registers an exception handler and will print the exception's message to the end user and exit the programm with a non-zero exit code. You can disable this behaviour and catch all exceptions yourself by passing false to the constructor.

You can use the provided splitbrain\phpcli\Exception to signal any problems within your main code yourself. The exception's code will be used as the exit code then.

Stacktraces will be printed on log level debug.

Colored output

Colored output is handled through the Colors class. It tries to detect if a color terminal is available and only then uses terminal colors. You can always suppress colored output by passing --no-colors to your scripts. Disabling colors will also disable the emoticon prefixes.

Simple colored log messages can be printed by you using the convinence methods success() (green), info() (cyan), error() (red) or fatal() (red). The latter will also exit the programm with a non-zero exit code.

For more complex coloring you can access the color class through $this->colors in your script. The wrap() method is probably what you want to use.

The table formatter allows coloring full columns. To use that mechanism pass an array of colors as third parameter to its format() method. Please note that you can not pass colored texts in the second parameters (text length calculation and wrapping will fail, breaking your texts).

Table Formatter

The TableFormatter class allows you to align texts in multiple columns. It tries to figure out the available terminal width on its own. It can be overwritten by setting a COLUMNS environment variable.

The formatter is used through the format() method which expects at least two arrays: The first defines the column widths, the second contains the texts to fill into the columns. Between each column a border is printed (a single space by default).

See the example/table.php for sample usage.

Columns width can be given in three forms:

When mixing fixed and percentage widths, percentages refer to the remaining space after all fixed columns have been assigned.

Space for borders is automatically calculated. It is recommended to always have some relative (percentage) or a fluid column to adjust for different terminal widths.

The table formatter is used for the automatic help screen accessible when calling your script with -h or --help.

PSR-3 Logging

The CLI class is a fully PSR-3 compatible logger (printing colored log data to STDOUT and STDERR). This is useful when you call backend code from your CLI that expects a Logger instance to produce any sensible status output while running.

If you need to pass a class implementing the Psr\Log\LoggerInterface you can do so by inheriting from one of the two provided classes implementing this interface instead of splitbrain\phpcli\CLI.

The resulting object then can be passed as the logger instance. The difference between the two is in adjusted method signatures (with appropriate type hinting) only. Be sure you have the suggested psr/log composer package installed when using these classes.

Note: if your backend code calls for a PSR-3 logger but does not actually type check for the interface (AKA being LoggerAware only) you can also just pass an instance of splitbrain\phpcli\CLI.

Log Levels

You can adjust the verbosity of your CLI tool using the --loglevel parameter. Supported loglevels are the PSR-3 loglevels and our own success level:

Convenience methods for all log levels are available. Placeholder interpolation as described in PSR-3 is available, too. Messages from warning level onwards are printed to STDERR all below are printed to STDOUT.

The default log level of your script can be set by overwriting the $logdefault member.

See example/logging.php for an example.


All versions of php-cli with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package splitbrain/php-cli contains the following files

Loading the files please wait ....