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
14 require_once 'XML/XRD/Serializer/Exception.php';
17 * Serialization dispatcher - loads the correct serializer for saving XRD data.
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
26 class XML_XRD_Serializer
36 * Init object with xrd object
38 * @param XML_XRD $xrd Data storage the data are fetched from
40 public function __construct(XML_XRD $xrd)
46 * Convert the XRD data into a string of the given type
48 * @param string $type File type: xml or json
50 * @return string Serialized data
52 public function to($type)
54 return (string)$this->getSerializer($type);
58 * Creates a XRD loader object for the given type
60 * @param string $type File type: xml or json
62 * @return XML_XRD_Loader
64 protected function getSerializer($type)
66 $class = 'XML_XRD_Serializer_' . strtoupper($type);
67 $file = str_replace('_', '/', $class) . '.php';
69 if (class_exists($class)) {
70 return new $class($this->xrd);
73 throw new XML_XRD_Serializer_Exception(
74 'No serializer for type "' . $type . '"',
75 XML_XRD_Loader_Exception::NO_LOADER