public function fromMessage($message)
    {
        static $parser;
        if (!$parser) {
            $parser = new MessageParser();
        }

        // Parse a response
        if (strtoupper(substr($message, 0, 4)) == 'HTTP') {
            $data = $parser->parseResponse($message);
            return $this->createResponse(
                $data['code'],
                $data['headers'],
                $data['body'] === '' ? null : $data['body'],
                $data
            );
        }

        // Parse a request
        if (!($data = ($parser->parseRequest($message)))) {
            throw new \InvalidArgumentException('Unable to parse request');
        }

        return $this->createRequest(
            $data['method'],
            Url::buildUrl($data['request_url']),
            [
                'headers' => $data['headers'],
                'body' => $data['body'] === '' ? null : $data['body'],
                'config' => [
                    'protocol_version' => $data['protocol_version']
                ]
            ]
        );
    }
public function fromMessage($message)
    {
        static $parser;
        if (!$parser) {
            $parser = new MessageParser();
        }

        // Parse a response
        if (strtoupper(substr($message, 0, 4)) == 'HTTP') {
            $data = $parser->parseResponse($message);
            return $this->createResponse(
                $data['code'],
                $data['headers'],
                $data['body'] === '' ? null : $data['body'],
                $data
            );
        }

        // Parse a request
        if (!($data = ($parser->parseRequest($message)))) {
            throw new \InvalidArgumentException('Unable to parse request');
        }

        return $this->createRequest(
            $data['method'],
            Url::buildUrl($data['request_url']),
            [
                'headers' => $data['headers'],
                'body' => $data['body'] === '' ? null : $data['body'],
                'config' => [
                    'protocol_version' => $data['protocol_version']
                ]
            ]
        );
    }
public function fromMessage ( $ message ) { static $ parser ; if ( ! $ parser ) { $ parser = new MessageParser ( ) ; } // Parse a response if ( strtoupper ( substr ( $ message , 0 , 4 ) ) == 'HTTP' ) { $ data = $ parser -> parseResponse ( $ message ) ; return $ this -> createResponse ( $ data [ 'code' ] , $ data [ 'headers' ] , $ data [ 'body' ] === '' ? null : $ data [ 'body' ] , $ data ) ; } // Parse a request if ( ! ( $ data = ( $ parser -> parseRequest ( $ message ) ) ) ) { throw new \ InvalidArgumentException ( 'Unable to parse request' ) ; } return $ this -> createRequest ( $ data [ 'method' ] , Url :: buildUrl ( $ data [ 'request_url' ] ) , [ 'headers' => $ data [ 'headers' ] , 'body' => $ data [ 'body' ] === '' ? null : $ data [ 'body' ] , 'config' => [ 'protocol_version' => $ data [ 'protocol_version' ] ] ] ) ; }
Create a request or response object from an HTTP message string

@param string $message Message to parse

@return RequestInterface|ResponseInterface
@throws \InvalidArgumentException if unable to parse a message
Create a request or response object from an HTTP message string