Skip to content

Instantly share code, notes, and snippets.

@Artistan
Forked from moiaune/CLI.class.php
Created September 24, 2015 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Artistan/a4d44291fc12c35703e3 to your computer and use it in GitHub Desktop.
Save Artistan/a4d44291fc12c35703e3 to your computer and use it in GitHub Desktop.
Simple IO class for php CLI.
/*
* Description: Simple IO class for php CLI
* Author: Mads Aune
*/
if(!defined("STDIN")) { define('STDIN', fopen('php://stdin', 'r')); }
class CLI {
public static function getLine($prompt = '') {
echo $prompt . "> ";
return trim(fgets(STDIN));
}
public static function getInt($prompt = '') {
echo $prompt . "> ";
$input = (int) trim(fgets(STDIN));
return is_numeric($input) ? $input : false;
}
public static function say($text = '') {
echo $text;
}
public static function sayLine($text = '') {
echo $text . "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment