public function readCommandInput($handle)
{
if (!is_resource($handle)) {
throw new RuntimeException(sprintf('Expected a resource stream for reading the commandline input. Got %s.', gettype($handle)));
}
if ($this->stdin !== null || ftell($handle) !== 0) {
return $this->stdin;
}
$input = '';
while (!feof($handle)) {
$input .= fread($handle, 1024);
}
// When the input only consist of white space characters, we assume that there is no input.
$this->stdin = !preg_match('/^([\\s]*)$/m', $input) ? $input : '';
return $this->stdin;
}