Phly\Http\AbstractSerializer::getLine PHP Method

getLine() protected static method

Retrieves a line from the stream; a line is defined as a sequence of characters ending in a CRLF sequence.
protected static getLine ( Psr\Http\Message\StreamInterface $stream ) : string
$stream Psr\Http\Message\StreamInterface
return string
    protected static function getLine(StreamInterface $stream)
    {
        $line = '';
        $crFound = false;
        while (!$stream->eof()) {
            $char = $stream->read(1);
            if ($crFound && $char === self::LF) {
                $crFound = false;
                break;
            }
            // CR NOT followed by LF
            if ($crFound && $char !== self::LF) {
                throw new UnexpectedValueException('Unexpected carriage return detected');
            }
            // LF in isolation
            if (!$crFound && $char === self::LF) {
                throw new UnexpectedValueException('Unexpected line feed detected');
            }
            // CR found; do not append
            if ($char === self::CR) {
                $crFound = true;
                continue;
            }
            // Any other character: append
            $line .= $char;
        }
        // CR found at end of stream
        if ($crFound) {
            throw new UnexpectedValueException("Unexpected end of headers");
        }
        return $line;
    }