Advertisement
bagnz0r

RPC Serializer

Oct 25th, 2011
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.78 KB | None | 0 0
  1. <?php defined('SYSPATH') or die('No direct script access.');
  2.  
  3. /**
  4.  * RPC Serializer for Kohana 3.2
  5.  * @author bagnz0r (http://bagnohax.pl)
  6.  */
  7.  
  8. class RpcSerializer {
  9.    
  10.     private $builder;
  11.     protected $data;
  12.    
  13.     /**
  14.      * Constructor will construct data object
  15.      *
  16.      * @param array $data
  17.      * @throws Kohana_Exception
  18.      */
  19.     public function __construct($data, $builder)
  20.     {
  21.         if (!is_array($data))
  22.             throw new Kohana_Exception('$data is not an array');
  23.        
  24.         $this->data = $data;
  25.        
  26.         // Load up builder
  27.         $class = 'rpcbuilder' . strtolower($builder);
  28.         $this->builder = new $class;
  29.     }
  30.    
  31.     /**
  32.      * This function returns serialized string of $this->data
  33.      *
  34.      * @return serialized_string
  35.      */
  36.     public function get()
  37.     {
  38.         return $this->builder->get($this->data);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement