final class Message{ /**
* Returns the string representation of an HTTP message.
*
* @param MessageInterface $message Message to convert to a string.
*/
public static function toString(MessageInterface
$message): string
{ if ($message instanceof RequestInterface
) { $msg =
trim($message->
getMethod().' '
.
$message->
getRequestTarget()) .' HTTP/'.
$message->
getProtocolVersion();
if (!
$message->
hasHeader('host'
)) { $msg .= "\r\nHost: ".
$message->
getUri()->
getHost();
} } elseif ($message instanceof ResponseInterface
) { $msg = 'HTTP/'.
$message->
getProtocolVersion().' '
.
$message->
getStatusCode().' '
.
$message->
getReasonPhrase();
} else { throw new \
InvalidArgumentException('Unknown message type'
);
}