Json and base64 encoders

parent 8170070b
Pipeline #7135 canceled with stages
......@@ -30,7 +30,7 @@ namespace core\Encoding;
class Base64
{
/**
* Encode stream
* Decode stream
*/
public static function decode($value)
{
......@@ -45,6 +45,30 @@ class Base64
fwrite($stream, base64_decode($chunk));
}
rewind($value);
rewind($stream);
return $stream;
}
}
/**
* Encode stream
*/
public static function encode($value)
{
if (is_scalar($value)) {
return base64_encode($value);
}
if (is_resource($value)) {
$stream = fopen('php://temp', 'w+');
while (!feof($value)) {
$chunk = fread($value, 1024*1024*2);
fwrite($stream, base64_encode($chunk));
}
rewind($value);
rewind($stream);
return $stream;
......
......@@ -77,7 +77,11 @@ class json
*/
public static function encode($data)
{
$jsonString = \json_encode($data, \JSON_PRETTY_PRINT + \JSON_UNESCAPED_SLASHES + \JSON_UNESCAPED_UNICODE);
require_once __DIR__.'/JsonSerializer.php';
$serializer = new JsonSerializer();
//$jsonString = \json_encode($data, \JSON_PRETTY_PRINT + \JSON_UNESCAPED_SLASHES + \JSON_UNESCAPED_UNICODE);
$jsonString = $serializer($data, \JSON_PRETTY_PRINT + \JSON_UNESCAPED_SLASHES + \JSON_UNESCAPED_UNICODE);
if ($jsonString === false) {
return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment