2024-04-19 16:15:46 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This Software is the property of Data Development and is protected
|
|
|
|
* by copyright law - it is NOT Freeware.
|
|
|
|
*
|
|
|
|
* Any unauthorized use of this software without a valid license
|
|
|
|
* is a violation of the license agreement and will be prosecuted by
|
|
|
|
* civil and criminal law.
|
|
|
|
*
|
|
|
|
* https://www.d3data.de
|
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
|
|
|
* @link http://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace D3\ModCfg\Application\Model\Encoding;
|
|
|
|
|
2024-06-26 13:49:30 +02:00
|
|
|
use JsonException;
|
|
|
|
|
2024-04-19 16:15:46 +02:00
|
|
|
class d3decoder
|
|
|
|
{
|
|
|
|
public const DEC_DEFAULT = 'default';
|
|
|
|
public const DEC_JSON = 'json';
|
|
|
|
public const DEC_UTF8 = 'utf-8';
|
|
|
|
public const DEC_GZIP = 'gzip';
|
|
|
|
public const DEC_SERIALIZE = 'serialize';
|
|
|
|
public const DEC_RAWURL = 'rawurl';
|
|
|
|
public const DEC_URL = 'url';
|
|
|
|
public const DEC_BASE64 = 'base64';
|
|
|
|
public const DEC_UUENC = 'uuencode';
|
|
|
|
public const DEC_QUOTED = 'quoted';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $_sDecodingType
|
|
|
|
*/
|
2024-06-26 13:49:30 +02:00
|
|
|
public function __construct(protected string $_sDecodingType = self::DEC_DEFAULT)
|
2024-04-19 16:15:46 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2024-06-26 13:49:30 +02:00
|
|
|
public function getDecodingType(): string
|
2024-04-19 16:15:46 +02:00
|
|
|
{
|
|
|
|
return $this->_sDecodingType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-06-26 13:49:30 +02:00
|
|
|
* @param string|null $encodedValue
|
2024-04-19 16:15:46 +02:00
|
|
|
*
|
2024-06-26 13:49:30 +02:00
|
|
|
* @return mixed
|
|
|
|
* @throws JsonException
|
2024-04-19 16:15:46 +02:00
|
|
|
*/
|
2024-06-26 13:49:30 +02:00
|
|
|
public function decode(?string $encodedValue): mixed
|
2024-04-19 16:15:46 +02:00
|
|
|
{
|
2024-06-26 13:49:30 +02:00
|
|
|
return match (strtolower($this->getDecodingType())) {
|
|
|
|
self::DEC_JSON => $this->decodeJson($encodedValue),
|
|
|
|
self::DEC_UTF8 => $this->decodeUtf8($encodedValue),
|
|
|
|
self::DEC_GZIP => $this->decodeGZip($encodedValue),
|
|
|
|
self::DEC_SERIALIZE => $this->decodeSerialize($encodedValue),
|
|
|
|
self::DEC_RAWURL => $this->decodeRawUrl($encodedValue),
|
|
|
|
self::DEC_URL => $this->decodeUrl($encodedValue),
|
|
|
|
self::DEC_BASE64 => $this->decodeBase64($encodedValue),
|
|
|
|
self::DEC_UUENC => $this->decodeUUEncode($encodedValue),
|
|
|
|
self::DEC_QUOTED => $this->decodeQuotedPrintable($encodedValue),
|
|
|
|
default => $this->decodeDefault($encodedValue)
|
|
|
|
};
|
2024-04-19 16:15:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-06-26 13:49:30 +02:00
|
|
|
* @param string|null $encodedValue
|
2024-04-19 16:15:46 +02:00
|
|
|
*
|
2024-06-26 13:49:30 +02:00
|
|
|
* @return mixed
|
2024-04-19 16:15:46 +02:00
|
|
|
*/
|
2024-06-26 13:49:30 +02:00
|
|
|
public function decodeDefault(?string $encodedValue): mixed
|
2024-04-19 16:15:46 +02:00
|
|
|
{
|
2024-06-26 13:49:30 +02:00
|
|
|
return unserialize(
|
|
|
|
rawurldecode(
|
|
|
|
base64_decode($encodedValue ?? '')
|
|
|
|
)
|
|
|
|
);
|
2024-04-19 16:15:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-06-26 13:49:30 +02:00
|
|
|
* @param string|null $encodedValue
|
2024-04-19 16:15:46 +02:00
|
|
|
*
|
2024-06-26 13:49:30 +02:00
|
|
|
* @return mixed
|
|
|
|
* @throws JsonException
|
2024-04-19 16:15:46 +02:00
|
|
|
*/
|
2024-06-26 13:49:30 +02:00
|
|
|
public function decodeJson(?string $encodedValue): mixed
|
2024-04-19 16:15:46 +02:00
|
|
|
{
|
2024-06-26 13:49:30 +02:00
|
|
|
return json_decode(
|
|
|
|
html_entity_decode($encodedValue ?? '', ENT_QUOTES),
|
|
|
|
null,
|
|
|
|
512,
|
|
|
|
JSON_THROW_ON_ERROR
|
|
|
|
);
|
2024-04-19 16:15:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-06-26 13:49:30 +02:00
|
|
|
* @param string|null $encodedValue
|
2024-04-19 16:15:46 +02:00
|
|
|
*
|
2024-06-26 13:49:30 +02:00
|
|
|
* @return mixed
|
2024-04-19 16:15:46 +02:00
|
|
|
*/
|
2024-06-26 13:49:30 +02:00
|
|
|
public function decodeUtf8(?string $encodedValue): mixed
|
2024-04-19 16:15:46 +02:00
|
|
|
{
|
2024-06-26 13:49:30 +02:00
|
|
|
return unserialize(
|
|
|
|
utf8_decode(
|
|
|
|
html_entity_decode($encodedValue ?? '', ENT_QUOTES)
|
|
|
|
)
|
|
|
|
);
|
2024-04-19 16:15:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-06-26 13:49:30 +02:00
|
|
|
* @param string|null $encodedValue
|
2024-04-19 16:15:46 +02:00
|
|
|
*
|
2024-06-26 13:49:30 +02:00
|
|
|
* @return mixed
|
2024-04-19 16:15:46 +02:00
|
|
|
*/
|
2024-06-26 13:49:30 +02:00
|
|
|
public function decodeSerialize(?string $encodedValue): mixed
|
2024-04-19 16:15:46 +02:00
|
|
|
{
|
2024-06-26 13:49:30 +02:00
|
|
|
return unserialize(
|
|
|
|
html_entity_decode($encodedValue ?? '', ENT_QUOTES)
|
|
|
|
);
|
2024-04-19 16:15:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-06-26 13:49:30 +02:00
|
|
|
* @param string|null $encodedValue
|
2024-04-19 16:15:46 +02:00
|
|
|
*
|
2024-06-26 13:49:30 +02:00
|
|
|
* @return mixed
|
2024-04-19 16:15:46 +02:00
|
|
|
*/
|
2024-06-26 13:49:30 +02:00
|
|
|
public function decodeUrl(?string $encodedValue): mixed
|
2024-04-19 16:15:46 +02:00
|
|
|
{
|
2024-06-26 13:49:30 +02:00
|
|
|
return unserialize(
|
|
|
|
urldecode($encodedValue ?? '')
|
|
|
|
);
|
2024-04-19 16:15:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-06-26 13:49:30 +02:00
|
|
|
* @param string|null $encodedValue
|
2024-04-19 16:15:46 +02:00
|
|
|
*
|
2024-06-26 13:49:30 +02:00
|
|
|
* @return mixed
|
2024-04-19 16:15:46 +02:00
|
|
|
*/
|
2024-06-26 13:49:30 +02:00
|
|
|
public function decodeRawUrl(?string $encodedValue): mixed
|
2024-04-19 16:15:46 +02:00
|
|
|
{
|
2024-06-26 13:49:30 +02:00
|
|
|
return unserialize(
|
|
|
|
rawurldecode($encodedValue ?? '')
|
|
|
|
);
|
2024-04-19 16:15:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-06-26 13:49:30 +02:00
|
|
|
* @param string|null $encodedValue
|
2024-04-19 16:15:46 +02:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2024-06-26 13:49:30 +02:00
|
|
|
public function decodeBase64(?string $encodedValue): mixed
|
2024-04-19 16:15:46 +02:00
|
|
|
{
|
2024-06-26 13:49:30 +02:00
|
|
|
return unserialize(
|
|
|
|
base64_decode($encodedValue ?? '')
|
|
|
|
);
|
2024-04-19 16:15:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-06-26 13:49:30 +02:00
|
|
|
* @param string|null $encodedValue
|
2024-04-19 16:15:46 +02:00
|
|
|
*
|
2024-06-26 13:49:30 +02:00
|
|
|
* @return mixed
|
2024-04-19 16:15:46 +02:00
|
|
|
*/
|
2024-06-26 13:49:30 +02:00
|
|
|
public function decodeGZip(?string $encodedValue): mixed
|
2024-04-19 16:15:46 +02:00
|
|
|
{
|
2024-06-26 13:49:30 +02:00
|
|
|
return unserialize(
|
|
|
|
gzdecode(
|
|
|
|
html_entity_decode($encodedValue ?? '', ENT_QUOTES)
|
|
|
|
)
|
|
|
|
);
|
2024-04-19 16:15:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-06-26 13:49:30 +02:00
|
|
|
* @param string|null $encodedValue
|
2024-04-19 16:15:46 +02:00
|
|
|
*
|
2024-06-26 13:49:30 +02:00
|
|
|
* @return mixed
|
2024-04-19 16:15:46 +02:00
|
|
|
*/
|
2024-06-26 13:49:30 +02:00
|
|
|
public function decodeUUEncode(?string $encodedValue): mixed
|
2024-04-19 16:15:46 +02:00
|
|
|
{
|
2024-06-26 13:49:30 +02:00
|
|
|
return unserialize(
|
|
|
|
convert_uudecode(
|
|
|
|
html_entity_decode($encodedValue ?? '', ENT_QUOTES)
|
|
|
|
)
|
|
|
|
);
|
2024-04-19 16:15:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-06-26 13:49:30 +02:00
|
|
|
* @param string|null $encodedValue
|
2024-04-19 16:15:46 +02:00
|
|
|
*
|
2024-06-26 13:49:30 +02:00
|
|
|
* @return mixed
|
2024-04-19 16:15:46 +02:00
|
|
|
*/
|
2024-06-26 13:49:30 +02:00
|
|
|
public function decodeQuotedPrintable(?string $encodedValue): mixed
|
2024-04-19 16:15:46 +02:00
|
|
|
{
|
2024-06-26 13:49:30 +02:00
|
|
|
return unserialize(
|
|
|
|
quoted_printable_decode(
|
|
|
|
html_entity_decode($encodedValue ?? '', ENT_QUOTES)
|
|
|
|
)
|
|
|
|
);
|
2024-04-19 16:15:46 +02:00
|
|
|
}
|
|
|
|
}
|