Download the PHP package webfiori/cli without Composer

On this page you can find all versions of the php package webfiori/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 cli

WebFiori CLI

Class library that can help in writing command line based applications with minimum dependencies using PHP.

Content

Supported PHP Versions

Build Status

Features

Sample Application

A sample application can be found here: https://github.com/WebFiori/cli/tree/main/example

Installation

To install the library, simply include it in your composer.json's require section: "webfiori\cli":"*".

Creating and Running Commands

Creating a Command

First step in creating new command is to create a new class that extends the class webfiori\cli\CLICommand. The class CLICommand is a utility class which has methods that can be used to read inputs, send outputs and use command line arguments.

The class has one abstract method that must be implemented. The code that will exist in the body of the method will represent the logic of the command.

Running a Command

The class webfiori\cli\Runner is the class which is used to manage the logic of executing the commands. In order to run a command, an instance of this class must be created and used to register the command and start running the application.

To register a command, the method Runner::register() is used. To start the application, the method Runner::start() is used.

Now if terminal is opened and following command is executed:

The output will be the string Hi People!.

Arguments

Arguments is a way that can be used to pass values from the terminal to PHP process. They can be used to configure execution of the command. For example, a command might require some kind of file as input.

Adding Arguments to Commands

Arguments can be added in the constructor of the class as follows:

Arguments can be provided as an associative array or array of objects of type webfiori\cli\Argument. In case of associative array, Index is name of the argument and the value of the index is sub-associative array of options. Each argument can have the following options:

The class webfiori\cli\Option can be used to access the options.

Accessing Argument Value

Accessing the value of an argument is performed using the method CLICommand::getArgValue(string $argName). If argument is provided, the method will return its value as string. If not provided, null is returned.

Interactive Mode

Interactive mode is a way that can be used to keep your application running and execute more than one command using same PHP process. To start the application in interactive mode, add the argument -i when starting the application as follows:

This will show following output in terminal:

help Command

One of the commands which comes by default with the library is the help command. It can be used to display help instructions for all registered commands.

Note: In order to use this command, it must be registered using the method Runner::register().

Setting Help Instructions

Help instructions are provided by the developer who created the command during its implementation. Instructions can be set on the constructor of the class that extends the class webfiori\cli\CLICommand as a description. The description can be set for the command and its arguments.

Running help Command

Help command can be used in two ways, one way is to display a general help for the application and another one for specific command.

General Help

To show general help of the application, following command can be executed.

Output of this command will be as follows:

Note: Depending on registered commands, output may differ.

Command-Specific Help

To show help instructions for a specific command, the name of the command can be included using the argument --command-name as follows:

Output of this command will be as follows:

Unit-Testing Commands

The library provides the helper class webfiori\cli\CommandTestCase which can be used to write unit tests for diffrent commands. The developer have to only extend the class and use utility methods to write tests. The class is based on PHPUnit.

The class has two methods which can be used to execute tests:

First method is good to verify the output of one specific command. The second one is usefule to simulate the execution of an application with multiple commands.

Both methods support simulating arguments vector and user inputs.

A sample of tests can be found here


All versions of cli with dependencies

PHP Build Version
Package Version
Requires webfiori/file Version 1.3.*
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 webfiori/cli contains the following files

Loading the files please wait ....