Spaces:
No application file
No application file
File size: 888 Bytes
d2897cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<?php
namespace Mautic\CoreBundle\Helper;
use Mautic\CoreBundle\Exception\InvalidDecodedStringException;
class ClickthroughHelper
{
/**
* Encode an array to append to a URL.
*/
public static function encodeArrayForUrl(array $array): string
{
return urlencode(base64_encode(serialize($array)));
}
/**
* Decode a string appended to URL into an array.
*
* @param bool $urlDecode
*
* @return array
*/
public static function decodeArrayFromUrl($string, $urlDecode = true)
{
$raw = $urlDecode ? urldecode($string) : $string;
$decoded = base64_decode($raw);
if (empty($decoded)) {
return [];
}
if (0 !== stripos($decoded, 'a')) {
throw new InvalidDecodedStringException($decoded);
}
return Serializer::decode($decoded);
}
}
|