Cleanup mime header parameter handling

This commit is contained in:
the-djmaze 2024-01-22 09:03:34 +01:00
parent 5747b7add6
commit 4d9fb41d73
2 changed files with 8 additions and 23 deletions

View file

@ -27,18 +27,17 @@ class Parameter implements \JsonSerializable
$this->sValue = $sValue;
}
public static function CreateFromParameterLine(string $sRawParam) : self
public static function FromString(string $sRawParam) : self
{
$oParameter = new self('', '');
return $oParameter->Parse($sRawParam);
}
public function Reset() : self
{
$this->sName = '';
$this->sValue = '';
$aParts = \explode('=', $sRawParam, 2);
$oParameter->sName = \trim(\trim($aParts[0]), '"\'');
if (2 === \count($aParts)) {
$oParameter->sValue = \trim(\trim($aParts[1]), '"\'');
}
return $this;
return $oParameter;
}
public function Name() : string
@ -56,20 +55,6 @@ class Parameter implements \JsonSerializable
$this->sValue = $sValue;
}
public function Parse(string $sRawParam, string $sSeparator = '=') : self
{
$this->Reset();
$aParts = \explode($sSeparator, $sRawParam, 2);
$this->sName = \trim(\trim($aParts[0]), '"\'');
if (2 === \count($aParts)) {
$this->sValue = \trim(\trim($aParts[1]), '"\'');
}
return $this;
}
public function ToString(bool $bConvertSpecialsName = false) : string
{
if (!\strlen($this->sName)) {

View file

@ -64,7 +64,7 @@ class ParameterCollection extends \MailSo\Base\Collection
$aDataToParse = \explode(';', $sRawParams);
foreach ($aDataToParse as $sParam) {
$this->append(Parameter::CreateFromParameterLine($sParam));
$this->append(Parameter::FromString($sParam));
}
$this->reParseParameters();