Piwigo/include/ws_protocols/json_encoder.php
Eike Rathke 8889f7ffef
issue #1575 PHP 8 compatibility, check for object type
* by using $response instanceof PwgError instead of get_class()
2022-07-21 17:27:37 +02:00

38 lines
1,009 B
PHP

<?php
// +-----------------------------------------------------------------------+
// | This file is part of Piwigo. |
// | |
// | For copyright and license information, please view the COPYING.txt |
// | file that was distributed with this source code. |
// +-----------------------------------------------------------------------+
class PwgJsonEncoder extends PwgResponseEncoder
{
function encodeResponse($response)
{
if ($response instanceof PwgError)
{
return json_encode(
array(
'stat' => 'fail',
'err' => $response->code(),
'message' => $response->message(),
)
);
}
parent::flattenResponse($response);
return json_encode(
array(
'stat' => 'ok',
'result' => $response,
)
);
}
function getContentType()
{
return 'text/plain';
}
}
?>