Phrozn\Runner\CommandLine\Reader::readLine PHP Method

readLine() public method

Get line from standard input
public readLine ( string $prompt ) : string
$prompt string Input prompt
return string
    public function readLine($prompt)
    {
        $this->getOutputter()->stdout($prompt);
        $out = fgets($this->getHandle());
        $this->getOutputter()->stdout("\n");
        return rtrim($out);
    }

Usage Example

Exemplo n.º 1
0
    public function testReader()
    {
        $handle = fopen(dirname(__FILE__) . '/stdin', 'w+');
        $outputter = new Outputter($this);
        $reader = new Reader($handle, $outputter);

        fputs($handle, "yes\n");

        $out = $reader->readLine("Input prompt:");
        //$this->assertSame("yes", $out);

        ob_start();
        var_dump($handle);
        $dump = trim(ob_get_clean());
        $this->assertTrue(strpos($dump, 'of type (stream)') > 0);

        unset($reader); // free up handler

        ob_start();
        var_dump($handle);
        $dump = trim(ob_get_clean());
        $this->assertTrue(strpos($dump, 'of type (Unknown)') > 0);

        unlink(dirname(__FILE__) . '/stdin');
    }