GrumPHP\IO\ConsoleIO::readCommandInput PHP Method

readCommandInput() public method

public readCommandInput ( resource $handle ) : string
$handle resource
return string
    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;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * @return FilesCollection
  */
 protected function getCommittedFiles(ConsoleIO $io)
 {
     if ($stdin = $io->readCommandInput()) {
         return $this->changedFilesLocator->locateFromRawDiffInput($stdin);
     }
     return $this->changedFilesLocator->locateFromGitRepository();
 }