You are here

function get_message_body_summary in Lockr 7.3

Get a short summary of the message body

Will return `null` if the response is not printable.

Parameters

MessageInterface $message The message to get the body summary:

int $truncateAt The maximum allowed size of the summary:

Return value

null|string

File

vendor/guzzlehttp/psr7/src/functions.php, line 852

Namespace

GuzzleHttp\Psr7

Code

function get_message_body_summary(MessageInterface $message, $truncateAt = 120) {
  $body = $message
    ->getBody();
  if (!$body
    ->isSeekable() || !$body
    ->isReadable()) {
    return null;
  }
  $size = $body
    ->getSize();
  if ($size === 0) {
    return null;
  }
  $summary = $body
    ->read($truncateAt);
  $body
    ->rewind();
  if ($size > $truncateAt) {
    $summary .= ' (truncated...)';
  }

  // Matches any printable character, including unicode characters:
  // letters, marks, numbers, punctuation, spacing, and separators.
  if (preg_match('/[^\\pL\\pM\\pN\\pP\\pS\\pZ\\n\\r\\t]/', $summary)) {
    return null;
  }
  return $summary;
}