public function test_getMsgEnvelop()
 {
     $actual = array('start' => '<option>', 'end' => '</option>');
     $_REQUEST['format'] = 'select';
     $result = getMsgEnvelop();
     //	$result['start'] = htmlentities($result['start']);
     //	$result['end'] = htmlentities($result['end']);
     //	var_export($result);
     $this->assertEquals($actual, $result);
 }
Ejemplo n.º 2
0
 function printServiceData($arrData, $format = null, $statusCode = 200)
 {
     if ($statusCode == null || !is_numeric($statusCode)) {
         $statusCode = 200;
     }
     $envelop = getMsgEnvelop();
     if ($format == null) {
         $format = $_REQUEST['format'];
     }
     if (getConfig("SERVICE_SHOW_REQUEST")) {
         $arrData['Request']['uri'] = SiteLocation . $GLOBALS['LOGIKS']["_SERVER"]['REQUEST_URI'];
         $arrData['Request']['site'] = $_REQUEST['site'];
         $arrData['Request']['scmd'] = $_REQUEST['scmd'];
         $arrData['Request']['format'] = $format;
         if (isset($GLOBALS['LOGIKS']["_SERVER"]["REQUEST_TIME_FLOAT"])) {
             $arrData['Request']['latency'] = microtime(true) - $GLOBALS['LOGIKS']["_SERVER"]["REQUEST_TIME_FLOAT"];
         } else {
             $arrData['Request']['latency'] = microtime(true) - $GLOBALS['LOGIKS']["_SERVER"]["REQUEST_SERVICE_START"];
         }
         $arrData['Request']['slug'] = array();
         foreach ($_REQUEST['slug'] as $key => $value) {
             $arrData['Request']['slug']["SLUG_{$key}"] = $value;
         }
     }
     $htmlFormats = array("list", "select", "table");
     if (in_array($format, $htmlFormats)) {
         if (isset($_REQUEST['debug']) && $_REQUEST['debug'] == "true") {
             header("Content-Type:text/text");
         } else {
             header("Content-Type:text/html");
         }
     } else {
         header("Content-Type:text/{$format}");
     }
     if (getConfig("SERVICE_SHOW_ERROR_CODE")) {
         header("Status: {$statusCode}");
         //header(':', true, $statusCode);
         header("HTTP/1.1 {$statusCode}");
     }
     $msgData = $arrData['Data'];
     // $msgData=array(
     // 		// "a"=>"m",
     // 		// "c"=>"n",
     // 		// "a","b",
     // 		// "a"=>array("x"=>array("m"=>"n"),"z"=>"w"),
     // 		// "b"=>array("m"=>"n","o"=>"p"),
     // 		// array("x"=>array("m"=>"n"),"z"=>"w"),
     // 		// array("m"=>"n","o"=>"p"),
     // 	);
     switch ($format) {
         case 'table':
             if (is_array($msgData)) {
                 if (isset($_REQUEST['autoformat']) && $_REQUEST['autoformat'] == "false") {
                     printFormattedArray($msgData, false, "table");
                 } else {
                     printFormattedArray($msgData, true, "table");
                 }
             } else {
                 echo "<tr><td>{$msgData}</td></tr>";
             }
             break;
         case 'list':
             if (is_array($msgData)) {
                 if (isset($_REQUEST['autoformat']) && $_REQUEST['autoformat'] == "false") {
                     printFormattedArray($msgData, false, "list");
                 } else {
                     printFormattedArray($msgData, true, "list");
                 }
             } else {
                 echo "<li>{$msgData}</li>";
             }
             break;
         case 'select':
             if (is_array($msgData)) {
                 if (isset($_REQUEST['autoformat']) && $_REQUEST['autoformat'] == "false") {
                     printFormattedArray($msgData, false, "select");
                 } else {
                     printFormattedArray($msgData, true, "select");
                 }
             } else {
                 echo "<option>{$msgData}</option>";
             }
             break;
         case 'xml':
             $xml = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><service></service>");
             arrayToXML($arrData, $xml);
             //array_walk_recursive($arrData, array ($xml, 'addChild'));
             echo $xml->asXML();
             break;
         case 'json':
             echo json_encode($arrData);
             break;
         case 'txt':
             if (is_array($msgData)) {
                 trigger_logikserror(900, E_USER_ERROR);
             } else {
                 $msgData = strip_tags($msgData);
                 echo $msgData;
             }
         default:
             //Anything else (raw,css,js)
             if (is_array($msgData)) {
                 printFormattedArray($msgData);
             } else {
                 $msgData = strip_tags($msgData);
                 echo $msgData;
             }
             break;
     }
 }