<?php
namespace ZBateson\MailMimeParser\Header\Part;
use Psr\Log\LoggerInterface;
use ZBateson\MbWrapper\MbWrapper;
class CommentPart extends ContainerPart
{
protected HeaderPartFactory $partFactory;
protected string $comment;
public function __construct(
LoggerInterface $logger,
MbWrapper $charsetConverter,
HeaderPartFactory $partFactory,
array $children
) {
$this->partFactory = $partFactory;
parent::__construct($logger, $charsetConverter, $children);
$this->comment = $this->value;
$this->value = '';
$this->isSpace = true;
$this->canIgnoreSpacesBefore = true;
$this->canIgnoreSpacesAfter = true;
}
protected function getValueFromParts(array $parts) : string
{
$partFactory = $this->partFactory;
return parent::getValueFromParts(\array_map(
function($p) use ($partFactory) {
if ($p instanceof CommentPart) {
return $partFactory->newQuotedLiteralPart([$partFactory->newToken('(' . $p->getComment() . ')')]);
} elseif ($p instanceof QuotedLiteralPart) {
return $partFactory->newQuotedLiteralPart([$partFactory->newToken('"' . \str_replace('(["\\])', '\$1', $p->getValue()) . '"')]);
}
return $p;
},
$parts
));
}
public function getComment() : string
{
return $this->comment;
}
public function getValue() : string
{
return '';
}
}