dev-master
9999999-devA skeleton for a Fortissimo CLI based application.
MIT
The Requires
by Matt Farina
skeleton console cli
Wallogit.com
2017 © Pedro Peláez
A skeleton for a Fortissimo CLI based application.
This is a skeleton project for building CLI applications using PHP, Fortissimo, and Composer., (*1)
Fortissimo is a chain-of-command based framework. This means you create reusable configurable parts called command containing some logic. Each callback (in the case of a CLI application we have CLI commands) executes a chain of these commands. Different callbacks can share commands. Yeah, I know this is a little abstract. More real world examples coming soon., (*2)
There are two ways you get started using this skeleton project. The simplest is to use composer create-project in a manner like:, (*3)
> composer create-project masterminds/fortissimo-cli-base foo-project-name
This will get you right up and going. Alternately you can grab this project right out of git. Then from the root of the project run composer install to install all the project dependencies. You should also update the composer.json file to include any dependencies of your own and add your psr-0 config component for autoloading., (*4)
This project is structured so you can hit the ground running. The usage expectation is the following:, (*5)
This is where all your custom code should go. Ideally it would be placed in here using a PSR-0 layout and the root composer.json file would be updated for this so you can use the composer autoloader., (*6)
This is where tests for your code should go. Test driven development is a great practice, right?!?!, (*7)
This directory contains a number of important files to get you right up and going., (*8)
For most applications only the _shared.php and compile.php files will need to be altered here and in most cases just for the custom name of the application., (*9)
I tend to think of the chain-of-command pattern like piping in PHP. Something like Yahoo Pipes but coded in PHP. This is where the chains are configured., (*10)
When the application bootstraps it includes each of the PHP files in this directory in alphabetical order to load the config options. The initial file 000-init.php is named so it is included first. This does some initial setup., (*11)
In files in this directory you write chains of commands. More detail and some examples coming soon., (*12)
Who wants a CLI application that's really a bunch of files and you have to call to some internal file? Not me. I prefer things with nice simple names and one file I can distribute. PHP Phar files let us do this as they can contain an entire project in a single file., (*13)
To execute these Phar files you'll need PHP and any dependencies on your operating system. Working on a Mac, everything I need is already bundled and available on that system., (*14)
Once you are ready to convert you application into a single file open up bin/compile.php so that it contains the name and proper location for your application. Then execute this file with php bin/compile.php and it will generate a Phar file for you., (*15)
Like composer these files can be run with php in fort of them or as self executing files., (*16)
Naming note: I often see phar files have the extension .phar. This is optional. You can create phar files with no extension and all. This along with self execution means you could write a CLI app like AwesomeSauce and just call that from the CLI. How you do this is entirely up to you. I'm just saying there are options., (*17)
This project is licensed under the MIT License., (*18)
A skeleton for a Fortissimo CLI based application.
MIT
skeleton console cli