Advertisement
sidson_aidson

Untitled

Jul 19th, 2020
1,416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  
  5. class Serializer{
  6.     private  $data = [];
  7.  
  8.     /**
  9.      * Serializer constructor.
  10.      * @param array $data
  11.      */
  12.     public function __construct(array $data)
  13.     {
  14.         $this->data = $data;
  15.     }
  16.  
  17.     public function  toJSONString(){
  18.         return json_encode($this->data);
  19.     }
  20.  
  21.     public function  toXLMString(){
  22.         $xml = new SimpleXMLElement('<root/>');
  23.         array_walk_recursive($this->data, array ($xml, 'addChild'));
  24.         return $xml->asXML();
  25.     }
  26.  
  27.     public function  toQueryString(){
  28.         return http_build_query($this->data);
  29.     }
  30.  
  31. }
  32.  
  33. abstract class CustomField{
  34.     private static $data = [];
  35.  
  36.     /**
  37.      * @return Serializer
  38.      */
  39.     public static function retrieve()
  40.     {
  41.         return new Serializer(self::$data);
  42.     }
  43. }
  44.  
  45. CustomField::retrieve()->toJSONString();
  46. CustomField::retrieve()->toXLMString();
  47. CustomField::retrieve()->toQueryString();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement