Skip to content

Commit

Permalink
#97: Wrap multiple-root XML responses with a <response> root tag
Browse files Browse the repository at this point in the history
  • Loading branch information
tyzoid committed Oct 22, 2017
1 parent adc218e commit a26a3bd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions source/Jacwright/RestServer/RestServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function handle() {
$this->data = $this->getData();
}

//preflight requests response
//preflight requests response
if ($this->method == 'OPTIONS' && getallheaders()->Access-Control-Request-Headers) {
$this->sendData($this->options());
}
Expand Down Expand Up @@ -231,7 +231,7 @@ protected function instantiateClass($obj) {

return false;
}

protected function initClass($obj) {
if (method_exists($obj, 'init')) {
$obj->init();
Expand Down Expand Up @@ -482,7 +482,7 @@ public function sendData($data) {
if ($this->useCors) {
$this->corsHeaders();
}

if ($this->format == RestFormat::XML) {
if (is_object($data) && method_exists($data, '__keepOut')) {
$data = clone $data;
Expand All @@ -491,6 +491,10 @@ public function sendData($data) {
}
}

if (is_array($data) && count($data) > 1) {
$data = array('response' => $data);
}

$this->xml_encode($data);
} else {
if (is_object($data) && method_exists($data, '__keepOut')) {
Expand Down Expand Up @@ -571,7 +575,7 @@ private function corsHeaders() {
header('Access-Control-Allow-Credential: true');
header('Access-Control-Allow-Headers: X-Requested-With, content-type, access-control-allow-origin, access-control-allow-methods, access-control-allow-headers, Authorization');
}

private $codes = array(
'100' => 'Continue',
'200' => 'OK',
Expand Down

0 comments on commit a26a3bd

Please sign in to comment.