Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php defined('SYSPATH') or die('No direct script access.');
- /**
- *
- * RPC Object Module for Kohana 3.2
- * The RPC object class
- *
- * @author bagnz0r (http://bagnohax.pl)
- * @package RpcObject
- *
- */
- class RpcObject {
- /**
- * Object data that will be serialized
- *
- * @var object
- */
- public $data;
- /**
- * Empty constructor does nothing
- */
- public function __construct() {}
- /**
- * An overload that will deserialize string and build data out of it
- *
- * @param string $string
- * @param string $deserializer For example: 'json' or 'xml'
- */
- public function __construct($string, $deserializer = 'json')
- {
- // Construct serializer/deserializer
- $class = 'rpcserializer' . $deserializer;
- // Deserialize data
- try {
- $this->data = $class::deserialize($string);
- }
- catch (Exception $e)
- {
- throw new Kohana_Exception('RpcObject: Could not deserialize data! Message: ' . $e->getMessage());
- }
- }
- /**
- * Serialize data as XML
- *
- * @return string
- */
- public function __toXml()
- {
- try {
- return RpcXmlSerializer::serialize($this->data);
- }
- catch (Exception $e)
- {
- throw new Kohana_Exception('RpcObject: Could not serialize data! Message: ' . $e->getMessage());
- }
- }
- /**
- * Serialize data as JSON
- *
- * @return string
- */
- public function __toJson()
- {
- try {
- return RpcJsonSerializer::serialize($this->data);
- }
- catch (Exception $e)
- {
- throw new Kohana_Exception('RpcObject: Could not serialize data! Message: ' . $e->getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement