class_BaseResponse.php

Go to the documentation of this file.
00001 <?php
00027 class BaseResponse extends BaseFrameworkSystem {
00031         private $responseStatus = "200 OK";
00032 
00036         private $responseHeaders = array();
00037 
00041         private $cookies = array();
00042 
00046         private $responseBody = "";
00047 
00051         private $templateInstance = null;
00052 
00056         private $fatalMessages = array();
00057 
00064         protected function __construct ($className) {
00065                 // Call parent constructor
00066                 parent::__construct($className);
00067 
00068                 // Clean up a little
00069                 $this->removeNumberFormaters();
00070                 $this->removeSystemArray();
00071         }
00072 
00079         public final function setResponseStatus ($status) {
00080                 $this->responseStatus = (string) $status;
00081         }
00082 
00090         public final function addHeader ($name, $value) {
00091                 $this->responseHeaders[$name] = $value;
00092         }
00093 
00099         public final function resetResponseHeaders () {
00100                 $this->responseHeaders = array();
00101         }
00102 
00109         public final function writeToBody ($output) {
00110                 $this->responseBody .= $output;
00111         }
00112 
00119         public final function setResponseBody ($output) {
00120                 $this->responseBody = $output;
00121         }
00122 
00130         public final function addFatalMessage ($messageId) {
00131                 // Adds the resolved message id to the fatal message list
00132                 $this->fatalMessages[] = $this->getApplicationInstance()->getLanguageInstance()->getMessage($messageId);
00133         }
00134 
00141         public final function addFatalMessagePlain ($message) {
00142                 // Adds the resolved message id to the fatal message list
00143                 $this->fatalMessages[] = $message;
00144         }
00145 
00155         public function flushBuffer ($force = false) {
00156                 if ((headers_sent()) && ($force === false)) {
00157                         // Headers are already sent!
00158                         throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT);
00159                 } elseif (!headers_sent()) {
00160                         // Send headers out
00161                         header("HTTP/1.1 {$this->responseStatus}");
00162 
00163                         // Used later
00164                         $now = gmdate('D, d M Y H:i:s') . ' GMT';
00165 
00166                         // General header for no caching
00167                         $this->addHeader('Expired', $now); // RFC2616 - Section 14.21
00168                         $this->addHeader('Last-Modified', $now);
00169                         $this->addHeader('Cache-Control', 'no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0'); // HTTP/1.1
00170                         $this->addHeader('Pragma', 'no-cache'); // HTTP/1.0
00171 
00172                         // Define the charset to be used
00173                         //$this->addHeader('Content-type:', sprintf("text/html; charset=%s", $this->getConfigInstance()->readConfig('header_charset')));
00174 
00175                         // Send all headers
00176                         foreach ($this->responseHeaders as $name => $value) {
00177                                 header("{$name}: {$value}");
00178                                 //* DEBUG: */ echo "{$name}: {$value}<br />\n";
00179                         } // END - foreach
00180 
00181                         // Send cookies out?
00182                         if (count($this->cookies) > 0) {
00183                                 // Send all cookies
00184                                 $cookieString = implode(" ", $this->cookies);
00185                                 header("Set-Cookie: {$cookieString}");
00186 
00187                                 // Remove them all
00188                                 $this->cookies = array();
00189                         } // END - if
00190                 }
00191 
00192                 // Are there some error messages?
00193                 if (count($this->fatalMessages) == 0) {
00194                         // Flush the output to the world
00195                         $this->getWebOutputInstance()->output($this->responseBody);
00196                 } else {
00197                         // Display all error messages
00198                         $this->getApplicationInstance()->handleFatalMessages($this->fatalMessages);
00199 
00200                         // Send the error messages out to the world
00201                         $this->getWebOutputInstance()->output($this->responseBody);
00202                 }
00203 
00204                 // Clear response header and body
00205                 $this->setResponseBody("");
00206                 $this->resetResponseHeaders();
00207         }
00208 }
00209 
00210 // [EOF]
00211 ?>

Generated on Mon Dec 8 01:06:46 2008 for Ship-Simulator by  doxygen 1.5.6