public function readWhile($callback, $peekLength = null)
    {
        if (!is_callable($callback)) {
            throw new \InvalidArgumentException(
                'Argument 1 passed to Reader->readWhile needs to be callback'
            );
        }

        if (!$this->hasLength()) {
            return;
        }

        if ($peekLength === null) {
            $peekLength = 1;
        }

        $result = '';
        while ($this->hasLength() && call_user_func($callback, $this->peek($peekLength))) {
            $result .= $this->consume();
        }

        return $result;
    }
public function readWhile($callback, $peekLength = null)
    {
        if (!is_callable($callback)) {
            throw new \InvalidArgumentException(
                'Argument 1 passed to Reader->readWhile needs to be callback'
            );
        }

        if (!$this->hasLength()) {
            return;
        }

        if ($peekLength === null) {
            $peekLength = 1;
        }

        $result = '';
        while ($this->hasLength() && call_user_func($callback, $this->peek($peekLength))) {
            $result .= $this->consume();
        }

        return $result;
    }
public function readWhile ( $ callback , $ peekLength = null ) { if ( ! is_callable ( $ callback ) ) { throw new \ InvalidArgumentException ( 'Argument 1 passed to Reader->readWhile needs to be callback' ) ; } if ( ! $ this -> hasLength ( ) ) { return ; } if ( $ peekLength === null ) { $ peekLength = 1 ; } $ result = '' ; while ( $ this -> hasLength ( ) && call_user_func ( $ callback , $ this -> peek ( $ peekLength ) ) ) { $ result .= $ this -> consume ( ) ; } return $ result ; }
Reads part of a string until it doesn't match the given callback anymore.

The string part is consumed directly, no `consume()` is required after `read()`-operations.

@param callable $callback   the callback to check string parts against.
@param int      $peekLength the length to peek for each iteration. (default: 1)

@return string|null the result string or null if finished reading.
Reads part of a string until it doesn t match the given callback anymore .