Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Serializer{
- private $data = [];
- /**
- * Serializer constructor.
- * @param array $data
- */
- public function __construct(array $data)
- {
- $this->data = $data;
- }
- public function toJSONString(){
- return json_encode($this->data);
- }
- public function toXLMString(){
- $xml = new SimpleXMLElement('<root/>');
- array_walk_recursive($this->data, array ($xml, 'addChild'));
- return $xml->asXML();
- }
- public function toQueryString(){
- return http_build_query($this->data);
- }
- }
- abstract class CustomField{
- private static $data = [];
- /**
- * @return Serializer
- */
- public static function retrieve()
- {
- return new Serializer(self::$data);
- }
- }
- CustomField::retrieve()->toJSONString();
- CustomField::retrieve()->toXLMString();
- CustomField::retrieve()->toQueryString();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement