Wallogit.com
2017 © Pedro Peláez
Simple PHP CLI Framework, (*1)
There are two ways to use lib-console., (*2)
composer.json file, (*3)
{
"require": {
"kasundon/lib-console": "~0.0.6"
}
}
php composer.phar install
Fist of all, Download latest console.phar., (*4)
curl -O https://github.com/KasunDon/lib-console/raw/master/build/console.phar
console.phar
php console.phar -help
place console.json file to your current working directory. Leave emtpty file_path in order to use current working directory., (*5)
{
"file_path": "commands/"
}
Simply implement Command Interface on to your custom command class., (*6)
console.phar - Dont forget to require_once follwoing statement before implements from Command Interface.require_once 'phar://console.phar/Command.php';
<?php
class Test implements Command {
/**
* Pre-execution command setup
*/
public function setup()
{
CommandUtility::log("pre command setup");
}
/**
* Executes command routines
*/
public function execute()
{
CommandUtility::log("execute");
}
/**
* Returns command name/description
*
* @return string
*/
public function getCommand()
{
return "Test Command";
}
}
Place app.php into current working directory and execute on following format. first argument is your custom command name. when pass in arguments use following format --abc 1., (*7)
Please note: class name will be use as command name., (*8)
php app.php Test --abc 1
console.phar
php console.phar Test --abc 1
lib-console automatically injecting input cli arguments into arguments property. you can simple use them as follows,, (*9)
$this->arguments