function Message::bodySummary
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:
File
-
vendor/
guzzlehttp/ psr7/ src/ Message.php, line 56
Class
Namespace
GuzzleHttp\Psr7Code
public static function bodySummary(MessageInterface $message, int $truncateAt = 120) : ?string {
$body = $message->getBody();
if (!$body->isSeekable() || !$body->isReadable()) {
return null;
}
$size = $body->getSize();
if ($size === 0) {
return null;
}
$body->rewind();
$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]/u', $summary) !== 0) {
return null;
}
return $summary;
}