Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Message.php

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

Message

Namespace

GuzzleHttp\Psr7

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal