Download the PHP package danc0/dcli without Composer
On this page you can find all versions of the php package danc0/dcli. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package dcli
Short Description A lightweight PHP CLI application framework.
License Unlicense
Informations about the package dcli
D-CLI
A Basic PHP CLI App Framework. This project is dependency free and meant to be a lightweight starting point for PHP CLI applications.
These docs are a work in progress as this project is still in development.
Full Documentation (For Beta Version)
Basic Setup
Install with: or download the latest package.
After creating your main file (ex: src/dcli
) ensure you make that file executable and optionally add it to your path so you can call your application from anywhere. You will also want to create a Composer autoload file.
The most basic setup uses anonymous functions to process commands.
This is the most basic possible usage and does not take advantage of sub commands.
Passing Class@method to Call
This method also does not make use of sub commands but allows you to move your logic into a class.
This will call the method in the class.
File Structure Controlled Commands
This method makes use of sub commands. To use the advanced structure a specific project layout is required. Your classes that will handle the commands must be placed in the directory. The command should be a sub folder. For example, the command should be placed in . Within that directory a file named should be created. This, and all classes in the directory should implement . This is the file that will be called on the command .
To use a sub command create an additional file with that sub-commands name. For example, would require you to make a file named with a class of in . This file will be called to process the sub command.
This requires a minimal setup in the main file.
The class handles the logic and routing of the calls.
Passing Arguments
Arguments are treated as key value pairs passed in the the key starting with the --
annotation. Arguments can be passed into the command in the following way:
The command parser will return John Smith
for the name
argument for either of these approaches.
The command runner will automatically set these variables within your class when it resolves the handler. For example, if you have a Default_Handler
with the argument name
available the command runner will add the value of name
to $this->name
within your class.
Passing Flags
Flags are considered booleans as can be passed with either -
or --
annotation.
The command runner will automatically set these variables within your class when it resolves the handler. For example, if you have a Default_Handler
with the flag v
available the command runner will set $this->v
to true or false depending on if it was passed or not.
Command_Container
The Command_Container holds information about your Config and your Request Environment. To tell the Command Runner to load this into your handler class you can do one of two things. First you can declare a variable in your class public Command_Container $Command_Container
this will be set AFTER the class is instantiated so you will not have access in the constructor, but will in the other methods of your class. If you need this available in your constructor function add Command_Container $Command_Container
as a variable that needs to be passed into the class.
Event_Handler Global
The main Application Event_Handler can be injected into your handler classes using the same two techniques outlined above for the Command_Container