HproseFormatter.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**********************************************************\
  3. | |
  4. | hprose |
  5. | |
  6. | Official WebSite: http://www.hprose.com/ |
  7. | http://www.hprose.net/ |
  8. | http://www.hprose.org/ |
  9. | |
  10. \**********************************************************/
  11. /**********************************************************\
  12. * *
  13. * HproseFormatter.php *
  14. * *
  15. * hprose formatter library for php5. *
  16. * *
  17. * LastModified: Nov 12, 2013 *
  18. * Author: Ma Bingyao <andot@hprfc.com> *
  19. * *
  20. \**********************************************************/
  21. require_once('HproseIOStream.php');
  22. require_once('HproseReader.php');
  23. require_once('HproseWriter.php');
  24. class HproseFormatter {
  25. public static function serialize(&$var, $simple = false) {
  26. $stream = new HproseStringStream();
  27. $hproseWriter = ($simple ? new HproseSimpleWriter($stream) : new HproseWriter($stream));
  28. $hproseWriter->serialize($var);
  29. return $stream->toString();
  30. }
  31. public static function &unserialize($data, $simple = false) {
  32. $stream = new HproseStringStream($data);
  33. $hproseReader = ($simple ? new HproseSimpleReader($stream) : new HproseReader($stream));
  34. return $hproseReader->unserialize();
  35. }
  36. }
  37. ?>