collection = $collection; } function getCollection() { return $this->collection; } function getHypermeida($accept = 'json') { $data = get_object_vars($this); switch ($accept) { case 'json': return json_encode($data); break; case 'xml': return $this->generateValidXmlFromArray($data); default : return json_encode($data); } } // functions adopted from http://www.sean-barton.co.uk/2009/03/turning-an-array-or-object-into-xml-using-php/ function generateValidXmlFromObj(stdClass $obj, $node_block = 'nodes', $node_name = 'node') { $arr = get_object_vars($obj); return self::generateValidXmlFromArray($arr, $node_block, $node_name); } function generateValidXmlFromArray($array, $node_block = 'nodes', $node_name = 'node') { $xml = ''; $xml .= '<' . $node_block . '>'; $xml .= self::generateXmlFromArray($array, $node_name); $xml .= ''; return $xml; } function generateXmlFromArray($array, $node_name) { $xml = ''; if (is_array($array) || is_object($array)) { foreach ($array as $key => $value) { if (is_numeric($key)) { $key = $node_name; } $xml .= '<' . $key . '>' . self::generateXmlFromArray($value, $node_name) . ''; } } else { $xml = htmlspecialchars($array, ENT_QUOTES); } return $xml; } } ?>