response = new DOMDocument('1.0', 'UTF-8'); $this->response_container = $this->response->createElement('Response'); } public function appendSection($section_title, $section_data) { $section = $this->response->createElement($section_title); foreach($section_data as $name => $value) { $section->appendChild( $this->response->createElement( $name, $value ) ); } $this->response_container->appendChild($section); } public function error($code = -1, $message = 'Unknown error.') { $error_element = $this->response->createElement('AuthorizationResponse'); $error_element->appendChild($this->response->createElement('ResponseCode', $code)); $error_element->appendChild($this->response->createElement('Message', $message)); $this->response_container->appendChild($error_element); $this->display(); } public function display() { @header('Content-Type: text/xml'); $this->response->appendChild($this->response_container); print $this->response->saveXML(); } } class ApiResponseJson { private $response = array(); public function __construct() { $this->response = array(); } public function appendSection($section_title, $section_data) { $this->response[$section_title] = $section_data; } public function error($code = -1, $message = 'Unknown error.') { $this->response['AuthorizationResponse'] = array( 'ResponseCode' => $code, 'Message' => $message ); $this->display(); } public function display() { @header('Content-Type: application/json'); print json_encode(array('Response' => $this->response)); } }