/** * finalSend * * @param int $statusCode * @return array|bool|string */ public function finalSend($statusCode = 200) { if ($this->statusCode) { $statusCode = $this->statusCode; } $headers = []; $headers['X-Powered-By'] = 'Computer Solutions Web Services'; $headers['Access-Control-Allow-Origin'] = '*'; $headers['Access-Control-Expose-Headers'] = 'X-Number-Of-Results, X-Powered-By, X-Error-Description'; $headers['Cache-Control'] = 'max-age=' . $this->cache . ',s-maxage=' . $this->cache . ' ,must-revalidate'; switch ($this->acceptHeader) { case 'json': $result = $this->arrayToSend; break; case 'custom+xml': $headers['Content-Type'] = 'application/xml'; $array2XML = new XmlArray($this->arrayToSend); $result = $array2XML->createXmlFromArray('results'); break; default: $array2HTML = new HTMLArray($this->arrayToSend); $result = $array2HTML->arrayToTable($this->arrayToSend); break; } return response($result, $statusCode, $headers); }
/** @test */ public function itCanConvertArrayToXml() { $array = [["alpha" => 1, "beta" => 2], ["alpha" => 3, "beta" => 4]]; $array2XML = new XmlArray($array); $result = $array2XML->createXmlFromArray('results'); $this->assertEquals(<<<'TAG' <?xml version="1.0" encoding="utf-8"?> <results><result><alpha>1</alpha><beta>2</beta></result><result><alpha>3</alpha><beta>4</beta></result></results> TAG , $result); }