PageRenderTime 45ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/Serialize.php

https://bitbucket.org/evinw/lib
PHP | 67 lines | 26 code | 17 blank | 24 comment | 0 complexity | 7bcde6b609810f4d5f9694a24a9288f7 MD5 | raw file
  1. <?php
  2. /**
  3. * @author Evin Weissenberg
  4. */
  5. class Serialize {
  6. private $subject; //object or array
  7. private $utf8;
  8. const CHARSET = 'default_charset';
  9. const ENCODING = 'UTF-8';
  10. /**
  11. *
  12. */
  13. private function __constructor() {
  14. $this->utf8 = ini_set(self::CHARSET, self::ENCODING);
  15. }
  16. /**
  17. * @param $subject
  18. * @return Serialize
  19. */
  20. public function setSubject($subject) {
  21. $this->subject = $subject;
  22. return $this;
  23. }
  24. /**
  25. * @return string
  26. */
  27. public function serialize() {
  28. $serialize = base64_encode(serialize($this->subject));
  29. return $serialize;
  30. }
  31. /**
  32. * @return string
  33. */
  34. public function unSerialize() {
  35. $un_serialize = base64_decode(unserialize($this->subject));
  36. return $un_serialize;
  37. }
  38. /**
  39. *
  40. */
  41. private function __destructor() {
  42. unset($this->subject);
  43. unset($this->utf8);
  44. }
  45. }
  46. //Usage
  47. //$array=array('Car','red','Boat'=>'white');
  48. //$obj = new Serialize();
  49. //$serialize = $obj->setSubject($array)->serialize();
  50. //print_r($serialize);