[Mime] added AbstractPart::asDebugString()

This commit is contained in:
Fabien Potencier 2019-08-04 06:55:52 +02:00
parent 35bf2fa9b5
commit f36c8c9881
5 changed files with 47 additions and 0 deletions

View File

@ -1,6 +1,11 @@
CHANGELOG CHANGELOG
========= =========
4.4.0
-----
* Added `AbstractPart::asDebugString()`
4.3.3 4.3.3
----- -----

View File

@ -74,6 +74,20 @@ abstract class AbstractMultipartPart extends AbstractPart
yield '--'.$this->getBoundary()."--\r\n"; yield '--'.$this->getBoundary()."--\r\n";
} }
public function asDebugString(): string
{
$str = parent::asDebugString();
foreach ($this->getParts() as $part) {
$lines = explode("\n", $part->asDebugString());
$str .= "\n".array_shift($lines);
foreach ($lines as $line) {
$str .= "\n |".$line;
}
}
return $str;
}
private function getBoundary(): string private function getBoundary(): string
{ {
if (null === $this->boundary) { if (null === $this->boundary) {

View File

@ -50,6 +50,11 @@ abstract class AbstractPart
yield from $this->bodyToIterable(); yield from $this->bodyToIterable();
} }
public function asDebugString(): string
{
return $this->getMediaType().'/'.$this->getMediaSubtype();
}
abstract public function bodyToString(): string; abstract public function bodyToString(): string;
abstract public function bodyToIterable(): iterable; abstract public function bodyToIterable(): iterable;

View File

@ -103,6 +103,16 @@ class DataPart extends TextPart
return $headers; return $headers;
} }
public function asDebugString(): string
{
$str = parent::asDebugString();
if (null !== $this->filename) {
$str .= ' filename: '.$this->filename;
}
return $str;
}
private function generateContentId(): string private function generateContentId(): string
{ {
return bin2hex(random_bytes(16)).'@symfony'; return bin2hex(random_bytes(16)).'@symfony';

View File

@ -144,6 +144,19 @@ class TextPart extends AbstractPart
return $headers; return $headers;
} }
public function asDebugString(): string
{
$str = parent::asDebugString();
if (null !== $this->charset) {
$str .= ' charset: '.$this->charset;
}
if (null !== $this->disposition) {
$str .= ' disposition: '.$this->disposition;
}
return $str;
}
private function getEncoder(): ContentEncoderInterface private function getEncoder(): ContentEncoderInterface
{ {
if ('8bit' === $this->encoding) { if ('8bit' === $this->encoding) {