Pop\Project\Install::cliInput PHP Метод

cliInput() публичный статический Метод

Return the (Y/N) input from STDIN
public static cliInput ( string $msg = null ) : string
$msg string
Результат string
    public static function cliInput($msg = null)
    {
        echo null === $msg ? I18n::factory()->__('Continue?') . ' (Y/N) ' : $msg;
        $input = null;
        while ($input != 'y' && $input != 'n') {
            if (null !== $input) {
                echo $msg;
            }
            $prompt = fopen("php://stdin", "r");
            $input = fgets($prompt, 5);
            $input = substr(strtolower(rtrim($input)), 0, 1);
            fclose($prompt);
        }
        return $input;
    }

Usage Example

Пример #1
0
     if (empty($argv[2]) || empty($argv[3])) {
         echo Install::cliError(1);
         // Else, check if the source folder exists
     } else {
         if (!file_exists($argv[2])) {
             echo Install::cliError(2);
             // Else, check if the output file ends in '.php'
         } else {
             if (strtolower(substr($argv[3], -4)) != '.php') {
                 echo Install::cliError(3);
                 // Else, generate the class map file
             } else {
                 echo 'Generating class map file \'' . $argv[3] . '\' from source folder \'' . $argv[2] . '\'' . PHP_EOL;
                 Classmap::generate($argv[2], $argv[3]);
                 // Add project to the bootstrap file
                 $input = Install::cliInput('Add classmap to the bootstrap file? (Y/N) ');
                 if ($input == 'y') {
                     $location = Install::getBootstrap();
                     $bootstrap = new File($location . '/bootstrap.php');
                     $bootstrap->write("\$autoloader->loadClassMap('" . addslashes(realpath($argv[3])) . "');" . PHP_EOL . PHP_EOL, true)->save();
                 }
                 echo 'Done.' . PHP_EOL . PHP_EOL;
             }
         }
     }
     // Else, install project
 } else {
     if ($argv[1] == '-i' || $argv[1] == '--install') {
         // Check if the project install file argument was passed
         if (empty($argv[2])) {
             echo Install::cliError(4);