Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Maarch
maarchRM
Commits
4a681714
Verified
Commit
4a681714
authored
Mar 03, 2020
by
Cyril Vazquez
Browse files
Json and base64 encoders
parent
8170070b
Pipeline
#7135
canceled with stages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
core/Encoding/Base64.php
View file @
4a681714
...
@@ -30,7 +30,7 @@ namespace core\Encoding;
...
@@ -30,7 +30,7 @@ namespace core\Encoding;
class
Base64
class
Base64
{
{
/**
/**
*
En
code stream
*
De
code stream
*/
*/
public
static
function
decode
(
$value
)
public
static
function
decode
(
$value
)
{
{
...
@@ -45,6 +45,30 @@ class Base64
...
@@ -45,6 +45,30 @@ class Base64
fwrite
(
$stream
,
base64_decode
(
$chunk
));
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
);
rewind
(
$stream
);
return
$stream
;
return
$stream
;
...
...
core/Encoding/json.php
View file @
4a681714
...
@@ -77,7 +77,11 @@ class json
...
@@ -77,7 +77,11 @@ class json
*/
*/
public
static
function
encode
(
$data
)
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
)
{
if
(
$jsonString
===
false
)
{
return
false
;
return
false
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment