Skip to content

Prompting User for Input

The Input class has methods to obtain user input as a prompt via the readline PHP extension.

To be able to read user input, you need to import the Input class. Then you need to create an Input object and call the read() method on it.

use Minicli\Input;

    $input=new Input();

    echo $userInput;
Below you find an example App that continuously reads user input in a loop and echoes it. By typing "end" you end the app.

#!/usr/bin/env php

if (php_sapi_name() !== 'cli') {

require __DIR__ . '/vendor/autoload.php';

use Minicli\App;
use Minicli\Command\CommandCall;

$app = new App();
$app->setSignature('./minicli mycommand');

$app->registerCommand('mycommand', function(CommandCall $input) {

    $input=new Input();

    echo $userInput;