1. Go to this page and download the library: Download codeinc/console library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
codeinc / console example snippets
use CodeInc\Console\Console;
// the parameter specifies if the class should throw exceptions
$console = new Console(true);
/*
* Asks a Yes / No question and returns a boolean
*/
// returns true or false
$console->askBool("Do you like chocolate?");
/*
* Asks a questions expecting a string as an answer
*/
// returns the response or null if no response is provided
echo $console->askString("What is your city?");
// returns the response or throws an exception if no response is provided
echo $console->askString("What is your city?", false);
/*
* Asks a questions with a closed list of anwsers
*/
$colors = ["green", "red", "blue", "purple", "orange", "yellow"];
// returns chosen color or throws an exception if no response is provided
echo $console->askOptions("What is your favorite color?", $colors);
// returns chosen color or null if no response is provided
echo $console->askOptions("What is your favorite color?", $colors, true);
use CodeInc\Console\CommandLine;
// returns true if the script is running in CLI mode
CommandLine::isCLI();
// returns true if the current user is 'root'
CommandLine::isRoot();
// returns true if the current user is 'username'
CommandLine::isUser("username");
// returns the current user name or null is the user is unknow.
CommandLine::getUser();
// thow an exception if not in CLI mode
CommandLine::