You are here

public static function Serializer::toString in Zircon Profile 8.0

Same name in this branch
  1. 8.0 vendor/zendframework/zend-diactoros/src/Request/Serializer.php \Zend\Diactoros\Request\Serializer::toString()
  2. 8.0 vendor/zendframework/zend-diactoros/src/Response/Serializer.php \Zend\Diactoros\Response\Serializer::toString()
Same name and namespace in other branches
  1. 8 vendor/zendframework/zend-diactoros/src/Request/Serializer.php \Zend\Diactoros\Request\Serializer::toString()

Serialize a request message to a string.

Parameters

RequestInterface $request:

Return value

string

File

vendor/zendframework/zend-diactoros/src/Request/Serializer.php, line 77

Class

Serializer
Serialize (cast to string) or deserialize (cast string to Request) messages.

Namespace

Zend\Diactoros\Request

Code

public static function toString(RequestInterface $request) {
  $headers = self::serializeHeaders($request
    ->getHeaders());
  $body = (string) $request
    ->getBody();
  $format = '%s %s HTTP/%s%s%s';
  if (!empty($headers)) {
    $headers = "\r\n" . $headers;
  }
  if (!empty($body)) {
    $headers .= "\r\n\r\n";
  }
  return sprintf($format, $request
    ->getMethod(), $request
    ->getRequestTarget(), $request
    ->getProtocolVersion(), $headers, $body);
}