src/Control/HTTPStreamResponse.php
protected function consumeStream($callback)
    {
        // Load from stream
        $stream = $this->getStream();
        if (!$stream) {
            return null;
        }

        // Check if stream must be rewound
        if ($this->consumed) {
            if (!$this->isSeekable()) {
                throw new BadMethodCallException(
                    "Unseekable stream has already been consumed"
                );
            }
            rewind($stream);
        }

        // Consume
        $this->consumed = true;
        return $callback($stream);
    }
protected function consumeStream($callback)
    {
        // Load from stream
        $stream = $this->getStream();
        if (!$stream) {
            return null;
        }

        // Check if stream must be rewound
        if ($this->consumed) {
            if (!$this->isSeekable()) {
                throw new BadMethodCallException(
                    "Unseekable stream has already been consumed"
                );
            }
            rewind($stream);
        }

        // Consume
        $this->consumed = true;
        return $callback($stream);
    }
protected function consumeStream ( $ callback ) { // Load from stream $ stream = $ this -> getStream ( ) ; if ( ! $ stream ) { return null ; } // Check if stream must be rewound if ( $ this -> consumed ) { if ( ! $ this -> isSeekable ( ) ) { throw new BadMethodCallException ( "Unseekable stream has already been consumed" ) ; } rewind ( $ stream ) ; } // Consume $ this -> consumed = true ; return $ callback ( $ stream ) ; }
Safely consume the stream

@param callable $callback Callback which will perform the consumable action on the stream
@return mixed Result of $callback($stream) or null if no stream available
@throws BadMethodCallException Throws exception if stream can't be re-consumed
Safely consume the stream