* @license PHP License * @package WB * @subpackage base */ WBClass::load( 'WBRest_Serializer' ); /** * REST Serializer / Unserializer JSON * * @version 0.1.1 * @package WB * @subpackage base */ class WBRest_Serializer_Json extends WBRest_Serializer { /** * format string of server error * * @var string */ protected $errorFrame = '{ "status": "error", "errors": [{ "code": "%d", "message": "%s" }] }'; /** * Unserialize Request * * Convert Request body to data array * * @param string $body * @return array $data */ public function unserialize($body) { $body = trim($body); $all = json_decode($body, true); if (!is_array($all)) { $all = array( 'data' => array() ); } else if (!isset($all['data']) || !is_array($all['data'])) { $all['data'] = array(); } return $all['data']; } /** * Serialize data * * Convert array data for response * * @param array $data * @return string $body */ public function serialize($data) { return json_encode($data); } }