Download the PHP package evo/cli without Composer

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

Command line interface options parser

The purpose of this library is to make a more user friendly way of setting command line arguments for programs.

It's fairly strait forward so I'll jump right in with an example (will call it 'program'):

This is the form of a typical command line call, here we are assuming only that PHP is executable on calling php. For windows users you may have to add the php.exe to the system environmental variables to call PHP this way. It's not hard to do and there are plenty of tutorials on how to do this for your version of windows. Otherwise you can always call PHP using the full path to the executable on your setup.

Class refrence

Cli Class Constants

Name Type Since Description
VERSION string 2.0.0 the current version
OPT_VALUE_EXPECTED string 2.0.0 Option: see Value Expected
OPT_MUST_VALIDATE string 2.0.0 Option: see Must Validate
OPT_MULTIPLE_EXPECTED string 2.0.0 Option: see Multiple Expected
R_ALL int 1.0.0 Bitwise Flag (composite of all bitwise other flags)
REQUEST_CLI int 1.0.0 Bitwise Flag Command line request
REQUEST_POST int 1.0.0 Bitwise Flag HTTP Post request
REQUEST_GET int 1.0.0 Bitwise Flag HTTP Get request
REQUEST_PUT int 1.0.0 Bitwise Flag HTTP Put/Post request
REQUEST_DELETE int 1.0.0 Bitwise Flag HTTP Delete/Post request

General Argument Definitions

Name Type Since Description
$conf array 1.0.0 An array of arguments to set (see below)
$shortName string 1.0.0 An arguments short name max length of 1, a-z A-Z or 0-9
$longName string 1.0.0 The long name for an argument or null, min length of 1, a-z A-Z or 0-9
$which string 1.0.0 Argument's shortName or longName, get an arguments value from request, null for get all
$default mixed 1.0.0 Default value to return when no value is set in the request ( can be a closure since 2.0.0 )
$options array 1.0.0 An array of options for the argument (see below)
$requestType int 1.0.0 One of the Cli::REQUEST_ constants or Cli::R_ALL (bitwise)
$request array 1.0.0 The request (typically auto detected)

Options (changed in 2.0.0)

Name Type Since Description
OPT_VALUE_EXPECTED bool 2.0.0 A value is expexed for this argument, if this is -a (false) otherwise -a (true)
OPT_MUST_VALIDATE mixed 2.0.0 If this argument is present then it's value must meet this condition
OPT_MULTIPLE_EXPECTED mixed 2.0.0 Multiple argements are exected, this argment value will always be an array when returned

OPT_VALUE_EXPECTED

When this option is true a value is expected for this argument:

OPT_MUST_VALIDATE

This option can be either a boolean value or a Closure (or any class that impliments the Callable interface):

OPT_MULTIPLE_EXPECTED

This option deturmines if an argument can have multiple values prog.exe -a=1 -a=2 -a=3

Basic Usage

Usage is pretty simple, there are 3 main methods you will need and few others that are just nice to have.

Cli is a "Singlton" which means you can only ever have one instance of the class. Calling getInstance again will return the same instance. This is fine because we can only handle one request at any give time. The main function you will use is $Cli->setArgument (or $Cli->fromConfig()) which defines what arguments you will accept from the request.

Above we are setting up a very basic argument to show the argument help document.

The first argument is shortName, h in this case, this is mainly what you use when referring to this argument. All incoming request data will be "normalized" to use the short name. Any items in the request that do not have a corresponding argument are simply ignored. In a command line call it will be referred to as -h, for a GET or POST request it will be referred to simply as h.

The second argument is the longName, help in this case. Any incoming arguments using the optional longName will be converted to their short name equivalent. In a command line call it will be referred to as --help, for a GET or POST request it will be referred to simply as help.

The third argument is the Help Doc. This string will be compiled with all the other arguments and retuned from getHelpDoc or output from printHelpDoc. It may also be appended to InvalidArgument exceptions thrown by the libary.

The fourth argument is an array of options, currently only 2 options are supported

This is equivalent to the previous code block where each argument was provided individually. It is up to the developer to decide how this is saved. There are some limitation due to using a closure as the 'accept' option. However this could be saved in a PHP file as an array:

And then included ( or required) as follows:

The flexabillity of a callback simply outweighs difficulty in saving a config in other format.

After all your arguments are defined you can access the values they hold in the request by using $Cli->getArguments(), Like this:

Other Methods

setAllowedRequestTypes

The first other method is $Cli->setAllowedRequestTypes($requestType). This sets which type of requests are allowed and is one of the Cli::REQUEST_* bitwise constants. Currently supported values are Cli::REQUEST_CLI, Cli::REQUEST_POST and Cli::REQUEST_GET. Multiple types can be set by seperating them with a single pipe |, like a typical PHP flag. The default is Cli::REQUEST_CLI.

The Cli::R_ALL is included for allow all, this value is subject to change if additonal request types are added. Such as those for a full REST framework.

setCurrentRequestTypes This method is provided to override the autodetection. This may be nessacary in the future when implimenting things like PUT and DELETE as no all servers support these HTTP Verbs. This accepts a single Cli::REQUEST_* constant. Currently it's of limited use.

setRequest This method allows you to inject a request array such as would come from the Command line, $_GET or $_POST Supper Globals. This is mostly for testing purposes. Where you can use a canned request array to run in something like a UnitTest.

getOptions This method returns the help documents for the currently supported options. It's mainly for ease of use by Developers using this library:

getHelpDoc This method returns the help document as a string, this is compiled from the $doc args of each argument that was set. This is mainly geared towards the command line and it is up to the developer to decide how to handle this for normal HTTP requests.

printHelpDoc This is simular to the above method except that it directly outputs the help document. You can supply an optional argument to call exit (which is typical when displaying help). The default is true set to false to continue script exection. For flexabillity it is up to the developer to decide what argument is used for help, but typically it is simply h and help. An example implimentation:

Install

You can get it from composer, by requiring it.

"require" : {
    "evo/cli" : "~1.0"
}

It has 2 dependancies (which are included in the composer.json file.

"require" : {
    "evo/cli" : "~1.0"
    "evo/patterns" : "~1.0",
    "evo/exception" : "dev-master"
}

And that is pretty much it, Enjoy!


All versions of cli with dependencies

PHP Build Version
Package Version
Requires php Version >=8.3
evo/patterns Version @stable
evo/exception Version @stable
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 evo/cli contains the following files

Loading the files please wait ....