PHP code example of mpyw / streamable-console

1. Go to this page and download the library: Download mpyw/streamable-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/ */

    

mpyw / streamable-console example snippets




namespace App\Console\Commands;

use Illuminate\Console\Command;

class QuizCommand extends Command
{
    protected $signature = 'example:quiz';

    /**
     * @return int
     */
    public function handle(): int
    {
        // We need to type "no" and press Enter to pass
        if ($this->confirm('Is one plus one equals to three?', true)) {
            return 1;
        }
        
        return 0;
    }
}



namespace App\Console\Commands;

use Illuminate\Console\Command;
use Mpyw\StreamableConsole\Streamable;

class RunCommand extends Command
{
    use Streamable;

    protected $signature = 'example:run';

    /**
     * @return int
     */
    public function handle(): int
    {
        // Type "no" and press Enter
        return $this->usingInputStream("no\n")->call('example:quiz');
    }
}



namespace App\Console\Commands;

use Illuminate\Console\Command;

class QuizCommand extends Command
{
    protected $signature = 'example:quiz';

    /**
     * @return int
     */
    public function handle(): int
    {
        // We need to type "no" and press Enter to pass at least for three times
        if ($this->confirm('Is one plus one equals to three?', true)) {
            return 1;
        }
        if ($this->confirm('Is one plus one equals to three?', true)) {
            return 1;
        }
        if ($this->confirm('Is one plus one equals to three?', true)) {
            return 1;
        }
        
        return 0;
    }
}



namespace App\Console\Commands;

use Illuminate\Console\Command;
use Mpyw\StreamableConsole\Streamable;

class RunCommand extends Command
{
    use Streamable;

    protected $signature = 'example:run';

    /**
     * @return int
     */
    public function handle(): int
    {
        // Infinitely type "no" and press Enter
        return $this->usingInfiniteInput("no\n")->call('example:quiz');
    }
}