* @package WB * @subpackage base */ WBClass::load( 'WBRest' ); /** * REST Serializer / Unserializer * * @version 0.3.0 * @package WB * @subpackage base */ class WBRest_Serializer extends WBStdClass { /** * format string of server error * * @var string */ protected $errorFrame = '%s: %s'; /** * debug flag * @param bool */ protected $debug = false; /** * Receive server error as formated string to send to response object * * @param string $no * @param string $msg * @return string */ public function sprintfError($no, $msg) { return sprintf($this->errorFrame, $no, $msg); } /** * Switch debug mode * * Allow to set debug flag * * @param bool $debug */ public function setDebug($debug) { $this->debug = $debug; } /** * Unserialize Request * * Convert Request body to data array * * @param string name of data element, if any * @return array $data */ public function unserialize($body, $dataElement = 'data') { return $this->extractUnserializedElement(array(), $dataElement); } /** * Select Element in Complete Data * * @param array complete data * @param string data element to extract * @return array */ final protected function extractUnserializedElement($all, $dataElement = 'data') { if (empty($dataElement)) { return $all; } if (!is_array($all)) { $all = array( $dataElement => array() ); } else if (!isset($all[$dataElement]) || !is_array($all[$dataElement])) { $all[$dataElement] = array(); } return $all[$dataElement]; } /** * Serialize data * * Convert array data for response * * @param array $data * @return string $body */ public function serialize($data) { return ''; } }