]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/LRDD/extlib/XML/XRD/Serializer.php
Implemented WebFinger and replaced our XRD with PEAR XML_XRD
[quix0rs-gnu-social.git] / plugins / LRDD / extlib / XML / XRD / Serializer.php
1 <?php
2 /**
3  * Part of XML_XRD
4  *
5  * PHP version 5
6  *
7  * @category XML
8  * @package  XML_XRD
9  * @author   Christian Weiske <cweiske@php.net>
10  * @license  http://www.gnu.org/copyleft/lesser.html LGPL
11  * @link     http://pear.php.net/package/XML_XRD
12  */
13
14 require_once 'XML/XRD/Serializer/Exception.php';
15
16 /**
17  * Serialization dispatcher - loads the correct serializer for saving XRD data.
18  *
19  * @category XML
20  * @package  XML_XRD
21  * @author   Christian Weiske <cweiske@php.net>
22  * @license  http://www.gnu.org/copyleft/lesser.html LGPL
23  * @version  Release: @package_version@
24  * @link     http://pear.php.net/package/XML_XRD
25  */
26 class XML_XRD_Serializer
27 {
28     /**
29      * XRD data storage
30      *
31      * @var XML_XRD
32      */
33     protected $xrd;
34
35     /**
36      * Init object with xrd object
37      *
38      * @param XML_XRD $xrd Data storage the data are fetched from
39      */
40     public function __construct(XML_XRD $xrd)
41     {
42         $this->xrd = $xrd;
43     }
44
45     /**
46      * Convert the XRD data into a string of the given type
47      *
48      * @param string $type File type: xml or json
49      *
50      * @return string Serialized data
51      */
52     public function to($type)
53     {
54         return (string)$this->getSerializer($type);
55     }
56
57     /**
58      * Creates a XRD loader object for the given type
59      *
60      * @param string $type File type: xml or json
61      *
62      * @return XML_XRD_Loader
63      */
64     protected function getSerializer($type)
65     {
66         $class = 'XML_XRD_Serializer_' . strtoupper($type);
67         $file = str_replace('_', '/', $class) . '.php';
68         include_once $file;
69         if (class_exists($class)) {
70             return new $class($this->xrd);
71         }
72
73         throw new XML_XRD_Serializer_Exception(
74             'No serializer for type "' . $type . '"',
75             XML_XRD_Loader_Exception::NO_LOADER
76         );
77     }
78 }
79 ?>