2024-05-07 12:17:25 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace GuzzleHttp;
|
|
|
|
|
|
|
|
|
|
use Psr\Http\Message\MessageInterface;
|
|
|
|
|
|
|
|
|
|
final class BodySummarizer implements BodySummarizerInterface
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @var int|null
|
|
|
|
|
*/
|
|
|
|
|
private $truncateAt;
|
|
|
|
|
|
2024-08-13 13:44:16 +00:00
|
|
|
public function __construct(?int $truncateAt = null)
|
2024-05-07 12:17:25 +02:00
|
|
|
{
|
|
|
|
|
$this->truncateAt = $truncateAt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a summarized message body.
|
|
|
|
|
*/
|
|
|
|
|
public function summarize(MessageInterface $message): ?string
|
|
|
|
|
{
|
|
|
|
|
return $this->truncateAt === null
|
2024-08-13 13:44:16 +00:00
|
|
|
? Psr7\Message::bodySummary($message)
|
|
|
|
|
: Psr7\Message::bodySummary($message, $this->truncateAt);
|
2024-05-07 12:17:25 +02:00
|
|
|
}
|
|
|
|
|
}
|