public function parse($raw)
    {
        $lines = explode("\n", $raw);

        // Status Line
        preg_match('/HTTP\/(\d\.\d) (\d\d\d) (.*)/', $lines[0], $statusLine);
        $response = (new Response())
            ->withProtocolVersion($statusLine[1])
            ->withStatus($statusLine[2], $statusLine[3]);
        unset($lines[0]);

        // Headers
        foreach ($lines as $i => $line) {
            if ('' == trim($line)) {
                unset($lines[$i]);
                break;
            }
            $header   = explode(': ', $line);
            $response = $response->withHeader($header[0], $header[1]);
            unset($lines[$i]);
        }

        // Body
        $stream = new Stream(fopen('php://memory', 'rw+'));
        $stream->write(implode("\n", $lines));
        $stream->rewind();
        $response = $response->withBody($stream);

        return $response;
    }
public function parse($raw)
    {
        $lines = explode("\n", $raw);

        // Status Line
        preg_match('/HTTP\/(\d\.\d) (\d\d\d) (.*)/', $lines[0], $statusLine);
        $response = (new Response())
            ->withProtocolVersion($statusLine[1])
            ->withStatus($statusLine[2], $statusLine[3]);
        unset($lines[0]);

        // Headers
        foreach ($lines as $i => $line) {
            if ('' == trim($line)) {
                unset($lines[$i]);
                break;
            }
            $header   = explode(': ', $line);
            $response = $response->withHeader($header[0], $header[1]);
            unset($lines[$i]);
        }

        // Body
        $stream = new Stream(fopen('php://memory', 'rw+'));
        $stream->write(implode("\n", $lines));
        $stream->rewind();
        $response = $response->withBody($stream);

        return $response;
    }
public function parse ( $ raw ) { $ lines = explode ( "\n" , $ raw ) ; // Status Line preg_match ( '/HTTP\/(\d\.\d) (\d\d\d) (.*)/' , $ lines [ 0 ] , $ statusLine ) ; $ response = ( new Response ( ) ) -> withProtocolVersion ( $ statusLine [ 1 ] ) -> withStatus ( $ statusLine [ 2 ] , $ statusLine [ 3 ] ) ; unset ( $ lines [ 0 ] ) ; // Headers foreach ( $ lines as $ i => $ line ) { if ( '' == trim ( $ line ) ) { unset ( $ lines [ $ i ] ) ; break ; } $ header = explode ( ': ' , $ line ) ; $ response = $ response -> withHeader ( $ header [ 0 ] , $ header [ 1 ] ) ; unset ( $ lines [ $ i ] ) ; } // Body $ stream = new Stream ( fopen ( 'php://memory' , 'rw+' ) ) ; $ stream -> write ( implode ( "\n" , $ lines ) ) ; $ stream -> rewind ( ) ; $ response = $ response -> withBody ( $ stream ) ; return $ response ; }
Parses a Raw HTTP response and converts it into a response object

@param string $raw
@return \Psr\Http\Message\Response
Parses a Raw HTTP response and converts it into a response object