예제 #1
0
 public function generate()
 {
     header('HTTP/1.1 ' . $this->_status . ' ' . RestEngine::getHTTPStatusMessage($this->_status));
     header('Content-Type: application/json');
     echo $this->_Result;
     exit;
 }
예제 #2
0
 public function processTags($output)
 {
     //Find the first special <restengine-status> tag and get its number value
     //Unsupported status code numbers will return 500 Internal Server Error.
     preg_match('#<restengine-status>(\\d\\d\\d)</restengine-status>[\\s?]#s', $output['output'], $statusTag);
     //Search for the first <restengine-headers> tag and get the tag contents as $headerTag variable for subsequent parsing
     preg_match('#<restengine-headers>.*?</restengine-headers>#s', $output['output'], $headerTags);
     //Delete the status code tag from frontend output if one was matched by the regex above
     //Set full HTTP Status code header with number from statusTag regex above
     if (count($statusTag) > 0) {
         $output['output'] = preg_replace('#' . preg_quote($statusTag[0], '#') . '#s', NULL, $output['output'], 1);
         header('HTTP/1.1 ' . $statusTag[1] . ' ' . RestEngine::getHTTPStatusMessage($statusTag[1]));
     }
     //If a set of special header tags are found by the regex above delete the tag from the output
     //and parse it into XML and create headers from the contents
     //or throw an error page if the string isn't valid XML.
     if (count($headerTags) > 0) {
         $output['output'] = preg_replace('#' . preg_quote($headerTags[0], '#') . '#s', NULL, $output['output'], 1);
         if (General::validateXML($headerTags[0], $errors, false)) {
             $headerTagsXML = new SimpleXMLElement($headerTags[0]);
             foreach ($headerTagsXML->header as $headerText) {
                 switch ((string) $headerText['action']) {
                     case "remove":
                         header_remove($headerText);
                         break;
                     case "replace":
                         header($headerText, true);
                         break;
                     default:
                         header($headerText, false);
                         break;
                 }
             }
         } else {
             //If logged in as a Symphony admin/author show a more detailed error message
             if (Symphony::Engine()->isLoggedIn()) {
                 $errorMessage = __('The following XML is not valid.') . '<p><code>' . General::sanitize($headerTags[0]) . '</code></p>' . __('Error %1$s', $errors);
             } else {
                 //Otherwise show a generic message.
                 $errorMessage = __('Invalid template HTTP header XML string.');
             }
             throw new SymphonyErrorPage($errorMessage, __('RestEngine Internal Server Error'));
         }
     }
 }
 public static function getSource()
 {
     return RestEngine::getSectionID();
 }
예제 #4
0
 public static function setPageData($pageData)
 {
     self::$_pageData = $pageData;
 }