Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F470857
JsonHandler.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
874 B
Referenced Files
None
Subscribers
None
JsonHandler.php
View Options
<?php
/**
* Mime Type: application/json
* @author Nathan Good <me@nategood.com>
*/
namespace
Httpful\Handlers
;
class
JsonHandler
extends
MimeHandlerAdapter
{
private
$decode_as_array
=
false
;
public
function
init
(
array
$args
)
{
$this
->
decode_as_array
=
!!(
array_key_exists
(
'decode_as_array'
,
$args
)
?
$args
[
'decode_as_array'
]
:
false
);
}
/**
* @param string $body
* @return mixed
*/
public
function
parse
(
$body
)
{
if
(
empty
(
$body
))
return
null
;
$parsed
=
json_decode
(
$body
,
$this
->
decode_as_array
);
if
(
is_null
(
$parsed
))
throw
new
\Exception
(
"Unable to parse response as JSON"
);
return
$parsed
;
}
/**
* @param mixed $payload
* @return string
*/
public
function
serialize
(
$payload
)
{
return
json_encode
(
$payload
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, May 6, 12:21 PM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
82071
Default Alt Text
JsonHandler.php (874 B)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment