Created
December 2, 2013 13:17
-
-
Save moiaune/7749294 to your computer and use it in GitHub Desktop.
Simple IO class for php CLI.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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